Accordingly to the is_page documentation, supplying the slug as an argument WP can tell me whether the current page is the one represented by the slug. Perhaps I am using the wrong slug?
However I did try both the path used in the rewrite argument as well as the bit I consider to be the “slug” or in other words the element used to register the CPT.
Please find below a code snippet to let you understand:
'rewrite' => array( 'slug' => 'faqs/archivio' )
);
register_post_type( 'faqs', $args );
I did this a go using the slug used for a custom post type, but I wasn’t able to get this working.
So two questions?
- Is the is_page supposed to work in this case?
- if not, what the best alternative?
Thanks
Andrea
The creation of a custom post type have it inside the definition, a post type. Also is page only a default post type. If you register your custom post type, then check for this post type, not for a page.
Conditional Tag is_singular
The function, conditional tag is_singular()
main purpose is to check if viewing a singular post. However, it can also be used to check if viewing a singular post of a given post type by entering the $post_type
parameter as shown in the following code snippet.
is_singular( 'your_custom_post_type' );
or different post types
is_singular( array( 'your_custom_post_type_1', 'your_custom_post_type_2' ) );
Hint to debug
I use the plugin Debug Objects to debug topics in this context.
Maybe this helps you also, often easier as read the code or codex.
See the follow screenshot of the plugin, the result of the conditional tags, include is_page()
and is_single()
on a CPT.