Is it possible to remove “nextpage” tag inside posts text depending of utm_campaign ?

Depending of where my visitors are comming from, I want to remove the

<!--nextpage--> 

of my post.

I am using this

if($_GET['utm_campaign']== 'nonextpagecampaign') {

directly in my template in order to display or not things depending of the campaign name but for the nextpage tag, it’s not that easy.

2 Answers
2

You can use the_post hook to remove <!--nextpage-->. In this case:

add_action( 'the_post', 'campaign_remove_nextpage', 99);

function campaign_remove_nextpage ( $post ) {
    if ( ($_GET['utm_campaign']== 'nonextpagecampaign') && (false !== strpos( $post->post_content, '<!--nextpage-->' )) ) 
    {
        // Reset the global $pages:
        $GLOBALS['pages']     = [ $post->post_content ];

        // Reset the global $numpages:
        $GLOBALS['numpages']  = 0;

       // Reset the global $multipage:
        $GLOBALS['multipage'] = false;
    }
};

Read more about this issue

More in general, you may want to read this warning about SEO effects of using <!--nextpage-->.

Leave a Reply

Your email address will not be published. Required fields are marked *