Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

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

  • pioc34pioc34 Pézenas ✭✭

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

  • R_JR_J Ex-Fanboy Munich Admin

    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.

  • pioc34pioc34 Pézenas ✭✭

    Cool @R_J

    i will make my own plugin!

    R_J
  • R_JR_J Ex-Fanboy Munich Admin

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

  • pioc34pioc34 Pézenas ✭✭

    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>
    
    R_Jpioc34
Sign In or Register to comment.