admin管理员组文章数量:1122846
I'm trying to enqueue comment-reply.js script only on a certain page but something is wrong with my code. Can someone hint things here?
<?php if ( is_singular('1740') && (!is_home() || !is_front_page() || !is_single()) && comments_open() && get_option('thread_comments') ) wp_enqueue_script( 'comment-reply' ); ?>
I'm trying to enqueue comment-reply.js script only on a certain page but something is wrong with my code. Can someone hint things here?
<?php if ( is_singular('1740') && (!is_home() || !is_front_page() || !is_single()) && comments_open() && get_option('thread_comments') ) wp_enqueue_script( 'comment-reply' ); ?>
Share
Improve this question
edited Jan 29, 2017 at 17:12
prosti
4,3134 gold badges25 silver badges45 bronze badges
asked Jan 29, 2017 at 14:30
bpybpy
2995 silver badges20 bronze badges
2
|
2 Answers
Reset to default 0I think the conditional tag which is comments_open()
is not required. That checks if the comments are allowed for that specific page or not.
Try using the following code
<?php
if ( is_single('1740') ||
( !is_home() || !is_front_page() || !is_single() ) ) {
wp_enqueue_script( 'comment-reply' );
} ?>
comments_open()
requires the post ID for the specific posts to check whether the comments are allowed or not. So avoid using the condition for that.
Don't use is_singular()
with ID as it checks if a singular post is being displayed using the post type name as a parameter. Instead use is_single()
with using the post ID for which you wish to display.
In your above code, the flower bracket was missing too for the if condition.
Hope that helps the question you have asked.
Try adding the following code and let me know
if ( is_singular('1740') && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
本文标签: phpHow can I enqueue commentreply script only on certain page
版权声明:本文标题:php - How can I enqueue comment-reply script only on certain page? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736287929a1927985.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
is_singular()
accepts only str|array of post type name, not a post ID. You could useis_single
oris_page
. Unless1740
is a valid CPT :D – Ismail Commented Jan 29, 2017 at 15:30is_singular('1740')
. I ended up using this and it worked:<?php if ( is_page('1740')) {wp_enqueue_script( 'comment-reply' );} ?>
– bpy Commented Jan 29, 2017 at 19:12