How to add noindex on certain category

edited February 2017 in Vanilla 2.0 - 2.8

How to add meta noindex on certain vanilla category?
Is there any addon to make it easier adding meta noindex on one or more vanilla category?

Answers

  • Hi, do you find a way to do that? I want to noindex an entire category too

  • You would need a small plugin for that. It should also be possible with a custom theme, but I think something like that belongs to a plugin and not a theme...


       public function base_render_before($sender, $args) {
           if (!property_exists($sender, 'CategoryID')) {
               return;
           }
           if (!in_array($sender->CategoryID, [1,3,5])) {
               return;
           }
    
           $sender->Head->addTag(
               'meta',
               [
                   'name' => 'robots',
                   'content' => 'noindex, follow'
               ]
           );
        }
    

    This method needs to be inside of your plugin class. It checks if the current page belongs to one and only one category (like a discussion would) and afterwards checks if this category is in a list. You would have to customize that list or replace it with a direct comparison "$sender->CategoryID != 7"

    The last piece of code adds the noindex meta tag.

  • Cool @R_J

    i will make my own plugin!

  • You can pimp it up, by making the list of CategoryIDs configurable and upload it 👍️

  • I will try it

  • Or you can duplicate/edit your theme template

    <head>
      ...
      {if $Category.Name == 'this' || $Category.Name == 'that'}
       <META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
      {/if}
      ...
    </head>
    
Sign In or Register to comment.