【问题标题】:How can I pull a list of page tags from a WordPress plugin?如何从 WordPress 插件中提取页面标签列表?
【发布时间】:2020-08-25 11:05:41
【问题描述】:

我创建了一个从页面中提取标签列表的插件。如果我将它作为简码加载,它可以正常工作,如果我将它作为带有 add_action 的插件中的函数加载,它会返回 nada!有什么想法吗?

add_action( 'init', 'something_helper' );
function something_helper()
  {
     echo "the tags are: ".the_tags(); //returns nothing
  }

或者

function somefunction()
  {
     echo "the tags are: ".the_tags(); //returns tag list
  }
add_shortcode( 'shortcode_name', 'somefunction' );

【问题讨论】:

    标签: php wordpress plugins


    【解决方案1】:

    我发现的问题都在加载顺序中。为了解决这个问题,我通过更改在页脚中加载了我的函数:

    add_action( 'init', 'something_helper' );
    

    add_action( 'wp_footer', 'something_helper' );
    

    进行此更改后,我能够读取我的标签,甚至可以使用 if(has_tag('tagname')){} 为我的函数添加条件

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-16
      • 1970-01-01
      • 2018-11-12
      • 1970-01-01
      • 2013-11-29
      • 1970-01-01
      • 2012-12-12
      • 2014-10-25
      相关资源
      最近更新 更多