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
Add a comment  | 

1 Answer 1

Reset to default 0

Both 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