• Resolved wpraph

    (@wpraph)


    Hi there,

    I’m trying to do something that seems like it should be simple, but I’m having a heck of a time trying to track down the settings to make it happen — and I’ve not found a clear answer in any documentation or other tickets.

    What we need to do is have all posts within one specific category on our site be set to noindex, as a rule — so that (a) any existing posts within that category will be updated to be noindex and (b) any new posts created in that category moving forward will automatically be set to noindex as well.

    There’s a field on the WordPress category editing page for “Robots” in which you can add “noindex,” but in testing it, that doesn’t seem to have an effect on the actual posts within the associated category. (Maybe that’s about the category landing page?)

    Is there a setting somewhere within AIOSEO that’d make all the posts within a category be set to noindex and thus not visible to search engines?

    Thanks so much.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support MD. Sakib Khandaker

    (@numbnerd14)

    Hi @wpraph ,

    Thanks for reaching out!

    It’s true that, applying Noindex under All in One SEO > Search Appearance > Taxonomies will only apply to the taxonomy archive pages. It won’t apply to the posts/pages within those taxonomies.

    However, you can modify the code snippet (https://aioseo.com/docs/aioseo_robots_meta/) to achieve this.

    For your convenience, I’ve included a code snippet below, which you can apply to your site to test if it works for you. This code should set?the noindex, nofollow?attribute to all posts in a specific category.

    Please note that the code snippet below only works for post categories.

    /** Filter to set noindex to all posts of a specific category **/

    add_filter( 'aioseo_robots_meta', 'aioseo_filter_robots_meta' );

    function aioseo_filter_robots_meta ( $attributes ) {
    $categories = array_map( function ( $category ) {
    return $category->slug;
    }, get_the_category() );

    //Replace 'your_category' with your category slug.
    if ( in_array( 'your_category', $categories ) ) {
    unset($attributes);
    $attributes['noindex'] = 'noindex';
    $attributes['nofollow'] = 'nofollow';
    }
    return $attributes;
    }

    We recommend registering this filter through a custom plugin or the WPCode plugin.

    Here’s how to use WPCode –

    Open your WordPress Dashboard.

    1. Navigate to?Plugins > Add New.
    2. Search “WPCode” and install the first plugin you see in the result (https://a.supportally.com/13TQYH).
    3. After activating the WPCode, you’ll see “Code Snippets” in the left menu of WordPress. Click “Add Snippet“, as shown here –?https://a.supportally.com/JjHTOU.
    4. Now, you’ll see the “Add Your Custom Code (New Snippet)” option on the next screen. Please hover over that section and click the “Use Snippet” button (https://a.supportally.com/ceoues).
    5. Paste your code into the “Code Preview” Textarea field and give it a name like “Noindex ‘X’ category posts“. Please make sure to select “PHP Snippet” from the Code Type dropdown and toggle the status On (https://d.pr/WClcPV).
    6. Click the “Save Snippet” button to save the code (https://d.pr/ZnRI8L).

    Please let me know if you have any other questions.

    Plugin Support MD. Sakib Khandaker

    (@numbnerd14)

    Hi @wpraph ,

    We haven’t heard back from you in a couple of days.

    I’m going to go ahead and close this thread for now. But if you’d like us to assist, please feel welcome to continue the conversation.

    Thanks!

    Thread Starter wpraph

    (@wpraph)

    Hi there,

    Thanks for the helpful pointer, and apologies for my delayed response! (I was offline for a week and am just now getting caught up on everything that piled up while I was away…)

    This seems like exactly what we need. Much appreciated.

    Just one quick question: Would this be something we could simply add directly into our WordPress functions.php file, rather than adding another plugin onto the site to manage that? It looks like it, at a glance, but I wanted to make sure before attempting to do so…

    Thanks again.

    Plugin Support MD. Sakib Khandaker

    (@numbnerd14)

    Hi @wpraph ,

    Would this be something we could simply add directly into our WordPress functions.php file, rather than adding another plugin onto the site to manage that?

    Sure! You can add the code to your theme’s functions.php file, but we do recommend to at least use a child theme in that case so that you don’t lose the changes after a theme update.

    Taking a complete backup of your site before making any changes is recommended.

    Hope that helps! Let me know if you’ve any other questions.

    Thread Starter wpraph

    (@wpraph)

    Excellent! Thanks again.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.