我需要在文件函数中使用validation is\\u single(\'wordpress\')。php。
但是函数is\\u single()在文件函数中不起作用。php。
我可以在文件函数中使用的是\\u single()。php?
如果更多,则:
我在做一个检查,不管是不是单页。
对于单页,我设置了自定义功能。。
请帮帮我。
我需要在文件函数中使用validation is\\u single(\'wordpress\')。php。
但是函数is\\u single()在文件函数中不起作用。php。
我可以在文件函数中使用的是\\u single()。php?
如果更多,则:
我在做一个检查,不管是不是单页。
对于单页,我设置了自定义功能。。
请帮帮我。
is_single
很可能只在The Loop, 和functions.php
在循环之前加载。
您可以尝试以下方式:
add_action( \'wp_head\', function(){
var_dump(is_single());
});
现在你看到了is_single()
退货true
.编辑:我可能不喜欢建议它只在循环中起作用,但肯定有更好的地方is_single
比在functions.php
, 如果您正在检查页面的“单一性”,请等到您在正确的请求或模板中时再使用它。
新抄本:
警告:您只能在WordPress中的posts\\u selection操作挂钩之后使用条件查询标记(wp操作挂钩是第一个可以使用这些条件的挂钩)。For themes, this means the conditional tag will never work properly if you are using it in the body of functions.php, i.e. outside of a function.
但是:如果有对查询对象的引用(例如,从parse\\u query或pre\\u get\\u posts挂钩中),可以使用WP\\u query条件方法(例如:$query->;is\\u search())