admin管理员组文章数量:1379790
I am developing a theme framework for my own purposes.
So this time i am facing a problem, that is add_action
works out side conditional.
add_action( 'meanz_before_main_wrap', 'meanz_entry_header_structure_open', 5 );
add_action( 'meanz_before_main_wrap', function(){echo "<div class='title_cat'>";}, 6 );
add_action( 'meanz_before_main_wrap', function(){echo meanz_post_cats();}, 7 );
add_action( 'meanz_before_main_wrap', 'meanz_do_title', 25 );
add_action( 'meanz_before_main_wrap', function(){echo "</div>";}, 49 );
add_action( 'meanz_before_main_wrap', 'meanz_do_thumbnail', 50 );
add_action( 'meanz_before_main_wrap', 'meanz_entry_header_structure_close', 100 );
Otherwise if is use a conditional like this, it doesn't work
if(is_single()){
add_action( 'meanz_before_main_wrap', 'meanz_entry_header_structure_open', 5 );
add_action( 'meanz_before_main_wrap', function(){echo "<div class='title_cat'>";}, 6 );
add_action( 'meanz_before_main_wrap', function(){echo meanz_post_cats();}, 7 );
add_action( 'meanz_before_main_wrap', 'meanz_do_title', 25 );
add_action( 'meanz_before_main_wrap', function(){echo "</div>";}, 49 );
add_action( 'meanz_before_main_wrap', 'meanz_do_thumbnail', 50 );
add_action( 'meanz_before_main_wrap', 'meanz_entry_header_structure_close', 100 );
}
Don't know why it doesn't work. Any comments?
Sorry for wrong code. Updated the question.
I am developing a theme framework for my own purposes.
So this time i am facing a problem, that is add_action
works out side conditional.
add_action( 'meanz_before_main_wrap', 'meanz_entry_header_structure_open', 5 );
add_action( 'meanz_before_main_wrap', function(){echo "<div class='title_cat'>";}, 6 );
add_action( 'meanz_before_main_wrap', function(){echo meanz_post_cats();}, 7 );
add_action( 'meanz_before_main_wrap', 'meanz_do_title', 25 );
add_action( 'meanz_before_main_wrap', function(){echo "</div>";}, 49 );
add_action( 'meanz_before_main_wrap', 'meanz_do_thumbnail', 50 );
add_action( 'meanz_before_main_wrap', 'meanz_entry_header_structure_close', 100 );
Otherwise if is use a conditional like this, it doesn't work
if(is_single()){
add_action( 'meanz_before_main_wrap', 'meanz_entry_header_structure_open', 5 );
add_action( 'meanz_before_main_wrap', function(){echo "<div class='title_cat'>";}, 6 );
add_action( 'meanz_before_main_wrap', function(){echo meanz_post_cats();}, 7 );
add_action( 'meanz_before_main_wrap', 'meanz_do_title', 25 );
add_action( 'meanz_before_main_wrap', function(){echo "</div>";}, 49 );
add_action( 'meanz_before_main_wrap', 'meanz_do_thumbnail', 50 );
add_action( 'meanz_before_main_wrap', 'meanz_entry_header_structure_close', 100 );
}
Don't know why it doesn't work. Any comments?
Sorry for wrong code. Updated the question.
Share Improve this question asked May 17, 2020 at 4:34 Raashid DinRaashid Din 2182 silver badges19 bronze badges1 Answer
Reset to default 0is_single()
is not determined until the wp
hook, which runs after plugins and themes are loaded. So if you use it outside a hook, then it will always be false. If you need to define a bunch of hooks based on that condition, do it inside a callback for wp
:
add_action(
'wp',
function() {
if ( is_single() ) {
add_action( 'meanz_before_main_wrap', 'meanz_entry_header_structure_open', 5 );
add_action( 'meanz_before_main_wrap', function(){echo "<div class='title_cat'>";}, 6 );
add_action( 'meanz_before_main_wrap', function(){echo meanz_post_cats();}, 7 );
add_action( 'meanz_before_main_wrap', 'meanz_do_title', 25 );
add_action( 'meanz_before_main_wrap', function(){echo "</div>";}, 49 );
add_action( 'meanz_before_main_wrap', 'meanz_do_thumbnail', 50 );
add_action( 'meanz_before_main_wrap', 'meanz_entry_header_structure_close', 100 );
}
}
);
本文标签: theme developmentaddaction works outside condition but not inside it
版权声明:本文标题:theme development - add_action works outside condition but not inside it 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744466751a2607558.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论