Viewing 5 replies - 1 through 5 (of 5 total)
  • I don’t understand it in the complete sense, but does the following solves your issue?

    if( is_singular( 'my_custom_post_type' ) ) {
    // your code
    }
    
    if ( is_post_type_archive( 'my_custom_post_type' ) ) {
    // your code
    }
    
    
    Thread Starter danielgm

    (@danielgm)

    No, is_singular only recognizes post types, not post type templates. It’s like get_post_type which will just return ‘post’ no matter if the default or a custom post template is used.

    Are you referring to page templates for custom post types, as described here? Your link is for something else.

    Did you actually try is_page_template()? Because that function does work for posts and custom post types. I have just tested to confirm.

    I have a template, template-custom.php with this header:

    /**
     * Template Name: Custom Template
     * Template Post Type: post
     */
    

    When I assign it to a post, then is_page_template( 'template-custom.php' ) returns true.

    @danielgm Yes, that is right but my intention with suggesting is_singular is to check if the template is single template and the post type is the CPT. Anyways, I understand you are after something else.

    Please look at the @jakept ‘s revert

    Thread Starter danielgm

    (@danielgm)

    @jakept

    You’re right, that function does work for posts.

    I used the template name instead of the full file name when I tested.

    This worked for me:

    is_page_template( 'single-custom.php' )

    Thanks so much!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Still no is_post_template?’ is closed to new replies.