admin管理员组文章数量:1303551
How do I add my Custom Post Type "Single" items to this functions command?
add_action( 'wp_head', function () {
if( is_tax('country') || is_page('4090') ){
?>
<style>
@media (max-width: 768px) {
.site-content {
display: flex;
flex-direction: column-reverse;
}
}
</style>
<?php
}
} );
The above works great but I would also like to apply it to my Custom Post Type that is called:
conference_2021
I'd like the same function to apply also to all pages within the CPT "conference_2021"
I thought this would work but it doesn't:
if( is_single('conference_2021') || is_tax('country') || is_page('4090') ){
Am I missing something when trying to apply this to a CPT?
How do I add my Custom Post Type "Single" items to this functions command?
add_action( 'wp_head', function () {
if( is_tax('country') || is_page('4090') ){
?>
<style>
@media (max-width: 768px) {
.site-content {
display: flex;
flex-direction: column-reverse;
}
}
</style>
<?php
}
} );
The above works great but I would also like to apply it to my Custom Post Type that is called:
conference_2021
I'd like the same function to apply also to all pages within the CPT "conference_2021"
I thought this would work but it doesn't:
if( is_single('conference_2021') || is_tax('country') || is_page('4090') ){
Am I missing something when trying to apply this to a CPT?
Share Improve this question asked Feb 13, 2021 at 3:25 HenryHenry 9831 gold badge8 silver badges31 bronze badges 1- 2 developer.wordpress/reference/functions/is_singular – Michael Commented Feb 13, 2021 at 3:39
1 Answer
Reset to default 0Both is check single post existing or not.
But both function argument is different.
is_singular(). Pass argument for this post type slug
is_single() Pass argument for post ID, slug, title.
If you are use is_single() then check post type name.
Like: if ( is_single() && 'conference_2021' == get_post_type() ) { }
Ref: https://developer.wordpress/reference/functions/is_singular/ https://developer.wordpress/reference/functions/is_single/
本文标签: Trying to add Custom Post Type to this functionsphp command
版权声明:本文标题:Trying to add Custom Post Type to this functions.php command 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741753044a2395947.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论