[Support request] Adding "noindex" (only) on paginated content

Home Forums Support [Support request] Adding "noindex" (only) on paginated content

Home Forums Support Adding "noindex" (only) on paginated content

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1144417
    raysn

    Hi there,

    I wonder if it would be possible to automatically add the attribute “noindex” to paginated content via a filter in the functions.php of my GP-Child theme and remove “rel=next” from the first page, so that search engines are not redirected to the subpages at all.

    The background is the following: on the first page of a post (example.com/postname/) I display the whole content with several subheadings. This content should also be indexed by the search engines. Via <!–nextpage–> I divide the post into further subpages with only one heading each, i.e. example.com/postname/2/ etc. I use these subpages mainly to point users in social media only to a certain part of the content. For the search engines, these subpages /2/, /3/, etc. are completely unnecessary and generate a lot of duplicate content at this point. They don’t have to appear as single subpages in the search results, since I have the central landing page example.com/postname/ for this. Therefore, I would like to add the attribute “noindex” only to these subpages, but not to the landing page.

    In addition, it would certainly make sense to filter out “rel=next” from the landing page as well, since otherwise crawl budget would be wasted unnecessarily and the subpages would be “invisible” to the search engines anyway.

    What do I have to add to functions.php to achieve this? At https://wordpress.org/support/topic/how-to-add-noindex-nofollow-on-paginated-content/ I found a solution, but there are functions of the plugin “SEO Framework” mentioned, which I don’t use… I would definitely prefer a solution without additional plugin.

    Thank you for your efforts!

    Greets
    Raysn

    #1144860
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    You might be able to do something like this:

    add_action( 'wp_head', function() {
        global $numpages;
    
        if ( is_singular() && $numpages > 1 ) {
            echo '<meta name="robots" content="noindex">';
        }
    } );
    
    add_action( 'wp', function() {
        global $numpages;
    
        if ( is_singular() && $numpages > 1 ) {
            remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );
        }
    } );
    #1144885
    raysn

    Hi Tom,

    thanks for your response!

    Unfortunately, that doesn’t work for me. I guess that’s because the Yoast plugin overwrites general WordPress settings. I forgot to mention that I have the plugin in use.

    On the first page example.com/postname nothing seems to have changed in the head section (rel=”next” is still there), on the second, the paginated page, I now have two meta robots:
    <meta name=”robots” content=”max-snippet:-1, max-image-preview:large, max-video-preview:-1″> (probably what Yoast creates) and below <meta name=”robots” content=”noindex”> (added via the filter in functions.php)

    Do you have an idea for a workaround? I have looked at https://yoast.com/wordpress/plugins/seo/api/ and probably (if I understood correctly) wpseo_next_rel_link and the filter wpseo_robots should be changed… but I don’t know exactly what to do.

    By the way, I have already implemented a button to navigate through the paginated pages by using the following information in functions.php (I have already found the snippet here in the help section):

    add_filter( 'wp_link_pages_args', 'lh_wp_link_pages' ); 
    function lh_wp_link_pages( $args ) { 
        $args['next_or_number'] = 'next'; 
        $args['before'] = '<div style="text-align: center;">';
        return $args; 
    }

    What is the easiest way to hide this button on the first page (example.com/postname)?

    Thanks for your input!

    Greets
    Raysn

    #1145115
    Tom
    Lead Developer
    Lead Developer

    It seems Yoast used to have this option but removed it: https://yoast.com/pagination-seo-best-practices/

    You may need to contact their support to see if it’s possible to filter their default behavior.

    #1145134
    raysn

    Hm, unfortunately I don’t use a premium version of Yoast. And apparently Yoast’s support always refers to the article you linked to the same question anyway. I try to find a solution myself. Now that I have turned Yoast off for testing and used the code you mentioned, strangely enough not even the meta-robots attribute for /2/ has been added, which worked when Yoast was still active. Anyway, let’s see if I can fix this somehow. If I find a solution, I will post this here.

    #1145903
    Tom
    Lead Developer
    Lead Developer

    If they have a filter available where we can alter the default index/noindex, that would be best. Their support should be able to point to that filter if it exists.

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