wp_insert_link什么都没显示

I don't get how to use wp_insert_link correctly.

I used the code from reference

<?php
    $linkdata = array(
    'link_name' => 'WordPress Code Reference',
    'link_url' => 'https://developer.wordpress.org/reference'
    );

    $link_id = wp_insert_link( $linkdata );
?>

and also tried to integrate in some html tags like inside <div>, <a> or <p> or without them, but not able to see the result in the page.

For example I tried

<a href =<?php wp_insert_link('users.php')?>>test</a>

<a href =<?php echo wp_insert_link('users.php')?>>test</a>

The hyperlink appears, but it is not redirecting to any page.

Please suggest what I am missing.

As the documentation says the function returns:

The ID of the link (whether new or updated) on success.
On error, 0 if $wp_error is set to false. 
A WP_Error object if it is set to true.

That function is used to add a link in your WP installation, not for displaying it.


In order to display a link you would use the_permalink($id) which takes one parameter that is the current id of the page you want to link.

As the documentation says:

Retrieves the permalink for the current page (if in The Loop) or any arbitrary page ID if passed as the first argument. All arguments are optional. All arguments default to false.
If $id is passed, it will be the id of the page whose link is returned.
$leavename can be used to toggle off the switching out of "%pagename%" in permalinks.
$sample returns a sample permalink.

An example to link an existing page:

<a href="<?php the_permalink($pageID); ?>">permalink</a>

An example to link an the current page:

<a href="<?php the_permalink(); ?>">permalink</a>