doushizhou4477 2016-10-15 13:00
浏览 23

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.

  • 写回答

1条回答 默认 最新

  • duanchendu69495 2016-10-15 13:29
    关注

    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>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据