• Resolved Rolf Allard van Hagen

    (@ravanh)


    Hi, I was able to add a robots noindex header to all MailPoet subscription pages with this code snippet:

    add_filter(
    	'wp_headers',
    	function( $headers ) {
    		// Add noindex for feeds.
    		if ( is_singular( 'mailpoet_page' ) ) {
    			$headers['X-Robots-Tag'] = 'noindex, noarchive, nosnippet, follow';
    		}
    		return $headers;
    	}
    );

    However, this does not add the same header to Newsletter pages/endpoints style /?mailpoet_router&endpoint=view_in_browser&action=view&data=xxx

    Is there an easy way to detect those kind of queries or do I need to test for $_GET["mailpoet_router"]?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Rolf Allard van Hagen

    (@ravanh)

    UPDATE: I found that even testing for $_GET["mailpoet_router"] within a wp_headers filter does not work for these newsletter pages, so I guess that the regular WP hooks are bypassed?

    I ended up with this in my .htaccess to get the desired noindex header:

    <If "%{QUERY_STRING} =~ /mailpoet_router.*?/">
        Header set X-Robots-Tag "noindex, noarchive, nosnippet, follow"
    </If>
    Plugin Author MailPoet

    (@mailpoet)

    Yes, the “View in browser” endpoint bypasses the wp_headers filter, so you need to inject the header earlier for these pages.

    Example:

    add_filter(
        'wp_loaded',
    	function () {
    		if (isset($_GET["mailpoet_router"], $_GET['endpoint']) && $_GET['endpoint'] == 'view_in_browser') {
    			header('X-Robots-Tag: noindex, noarchive, nosnippet, follow');			
    		}
    	},
    	5
    );
    Thread Starter Rolf Allard van Hagen

    (@ravanh)

    Ok, that works! Thank you ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Noindex for newsletter endpoint pages’ is closed to new replies.