问题描述
我在网上找到了一个教程,其中展示了如何在 wordpress 中使用目录。有一个代码,代码是
if ( is_page( 'tocbot' ) ) {
wp_enqueue_script(
'tocbot',plugin_dir_url( __FILE__ ) . 'assets/js/tocbot.min.js',array(),'4.3.1',true
);
} // End if().
开发人员说,如果有条件,我们需要将 is_page( 'tocbot' ) 替换为您希望使用的 Tocbot。
我找到了教程 here
解决方法
使用 is_sgingle()
代替 is_page()
。
if ( is_sgingle() ) {
wp_enqueue_script(
'tocbot',plugin_dir_url( __FILE__ ) . 'assets/js/tocbot.min.js',array(),'4.3.1',true
);
} // End if().
,
所有 WordPress 条件的列表是 here。
在您的情况下,所有帖子都是 is_single
。对于帖子、页面和帖子类型,它是 is_singular
。