Looking to the problem from a different perspective, I’ve reached to a different solution to it.
I’ve created a function to check the post type instead of checking the slug of the post type.
Actually I was trying to assign different CSS Class to each post type
add_action( 'css_class_per_post_type', 'assign_css_class_to_each_post_type' ); // to be called in the place I want the class name to be displayed (I am using timber as the template engine)
function assign_css_class_to_each_post_type( $context ) {
$post_type = get_post_type($wp_query->post->ID);
$cssClass=""; // if no post type, no class is added
if ($post_type == 'project') {
$cssClass="projects-listing-cpt";
}
if ($post_type == 'music') {
$cssClass="musics-listing-cpt";
}
echo $cssClass;
}
Related Posts:
- How do test if a post is a custom post type?
- Exclude custom function content from certain pages
- Conditional for a Single Post That Belongs to a Category?
- If custom taxonomy else conditional [closed]
- Conditional for single-{post-type}.php
- If Post Type equals, then display X content
- Display several random posts, but make sure a condition is met
- is_singular() not working if called via callback function of admin-ajax.php
- functions.php conditional tag only for custom post type
- Get template part based on custom taxonomy term
- If on term-page -> get the current term?
- custom post type upcoming post and past post
- changing default comment form arguments [duplicate]
- Function like in_category for custom taxonomies
- is_page_template not working as expected
- remove child post from custom post type archive
- if custom posts type exists and there are posts load script
- Need help targeting a custom post type with conditional tags
- Why would this IF statement not work? [closed]
- custom comments on specific post type
- Excluding custom post types
- Can I create a loop with multiple post types and specify different $args for each post type?
- Conditional PNG Overlay in Custom Post Type Loop Depending on Post Type
- Register widget only page is a singular of custom post type
- Is there a conditional tag to determine whether the post is _any_ custom post type?
- Conditional Query of Custom Post Type and custom taxonomy
- How to run filter only on custom post type edit screen
- Conditional statement for if archive page has posts which contain certain taxonomies/categories/tags, show those terms
- Custom Post Conditional for Parent & Child Single.php?
- Search filter triggered & sort by custom post type
- How to show only the most recent post on my custom post type archive?
- Dynamically output a class to an anchor tag depending on what tag is chosen
- Conditional Tags for specific category of custom posts
- Move Genesis Single Page/Single Post Title
- Check IF single OR multiple custom data has been entered
- How to check if post/page or taxonomy post is published by admin
- TinyMCE Buttons on Certain Post Type
- Display message if no posts in Custom Post Type loop
- Showing taxonomy terms on custom post type
- Check if custom post is a parent?
- Redirect to URL if x number of days passed
- comments hooks on custom post type
- Conditional Statements
- If tag exists, then echo once
- Show specific content on parent custom post type and all children
- Use conditionals with wp_enqueue_style to attach stylesheet according to post type displayed
- Checking for custom field in admin pages
- I’m trying to create an if statement that will only display my button link for tickets if its under ‘admission-event’… what is wrong with my code?
- How to add custom PHP code in post header?
- $_SESSION Not working after X amount of page views
- Multiple domains, Single database, 1 Parent/Master with all content, other domains/slaves with filtered content (based on “location” variable)
- conditional based upon the count of current user’s published custom posts
- Display content based on Author Custom Post type
- Custom metabox fields not saving when limited to a certain CPT
- Can not hook into custom post type template with: is_page() conditional?
- Diffrent search templates for different post types
- Conditional Tags If Custom Post Parent & Child?
- Custom Post Query Combined with Conditional Tags
- Loop to pull content from parent element in custom post type [duplicate]
- Conditional statement checking two conditions for CPT and Custom Taxonomy [closed]
- strange conditional tag behaviour [duplicate]
- How to set up a echo? [closed]
- Custom post type is_singular condtional not working when managing sidebar display
- Taxonomy term in permalink
- How to give a CPT (custom post type) a date based url
- get_edit_post_link() not working as expected when passed id in plugin
- ‘No pages found’ in Dashboard after registering custom taxonomy
- Issue with saving custom post type when editor is removed
- How would I leverage custom Taxonomies in this scenario?
- How to display recent posts added in custom post types
- 2 different post->IDs for single page load only in Firefox
- Display custom post types with custom date field value (before today) & order by custom date field
- Using pre_get_posts to filter one loop in a multiloop archive
- How to Duplicate (multiple meta box)?
- Custom Post Type: Upload Multiple Images
- How Do You Add a Second “Posts” Menu to Your Dashboard?
- Is $object_type truly required with register_taxonomy()?
- Suggested Post and Taxonomy structure
- frontend image post uploader
- admin-ajax.php GET custom-post titles
- How to group search results by post type and only if post type result is not empty?
- Allow contributor to edit own posts after published, without plugin
- Show current user posts in custom post type query
- Custom taxonomy template shows 404 Error
- Custom Post Type with modified permalink structure results in 404
- Saving custom post in custom form
- Advanced custom field – posted fields from custom post type
- returning the currect URL for nested posts
- How to make comments for custom post type best way
- Display custom post types in dropdown with option “all”
- Query a Custom Post Type using SELECT that has ACF fields to compare dates
- Hierarchical Custom Post Type Walker?
- Changing menu label to post name for custom post type
- Featured image in custom post is being disabled
- Best Method to Switch Between Terms (Custom Taxonomy)
- Permalinks when using Custom Post Type with static page for archive
- Query Only Show Text on Posts With Certain Taxonomy Tag
- Hierarchical Custom Post Types
- Custom Post Type featured option
- Rewrite rule taxonomy url with different values in one function