0

I've created the custom post type (CPT) called 'projects':

$post_type_args = array(
            //...
            'has_archive'          => true,
            'rewrite'              => array(
                // 'slug'       => '', // Defaults to $post_type key
                // 'with_front' => true, // Default true
                // 'feeds' => 'true', // Default has_archive value
                // 'pages' => true, // Default true
                // 'ep_mask' => EP_PERMALINK,
            ),
);

register_post_type( 'projects', $post_type_args );

And I would like the use a conditional tag only for the front page of the CPT. In my case is the page with the slug /projects.

I can use $_SERVER array like this:

if ( $_SERVER['REQUEST_URI'] == "/projects/" ) { //... }

But is there something like is_shop() conditional tag in WooCommerce for this case?

Thank you in advance.

1

there is an is_post_type_archive() function https://developer.wordpress.org/reference/functions/is_post_type_archive/ that will tell you if you are on the https://example.com/projects/ page.

In your case you would need to use it like this

is_post_type_archive( "projects" );

since "projects" is your custom post type name.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.