Adding index & noindex to Portfolio items

Hi Theme.co!

I am trying to block robots from indexing all portfolio items except for those in the “staff” category, and I haven’t been able to get it to work. Can you point me in the right direction?

Thank you for any advice you can offer!

add_action('wp_head', 'block_profiles');
function block_profiles(){
if ( is_singular( 'x-portfolio' ) ) {
    if ( is_category( 'staff' ) ) {
    	?>
            <meta name='robots' content='index, follow'/>
        <?php
    } else {
    	?>
            <meta name='robots' content='noindex, follow'/>
        <?php
    } };

Hello Nate,

Thanks for writing in!

Your code is somewhat correct except that you cannot use the is_category( 'staff' ) because the taxonomy of the Portfolio is “portfolio-category”. Since this is a custom taxonomy, you will have to use has_term(). Therefore, the condition would be:

has_term( 'staff', 'portfolio-category' )

Kindly let us know how it goes.

It worked like a charm!! --once I fixed a missing "}"

As always, thank you so much for your theme and great support!

No problem, Nate.
It’s the least that we could do for you.