WordPress.org

Ready to get started?Download WordPress

Forums

Plugin to add <! -- nexpage --> to posts (3 posts)

  1. westpointer
    Member
    Posted 6 years ago #

    Greetings - I created a plugin to add the nextpage tag after x number of paragraphs in a post. The plugin is inserting <! -- nextpage -- > (spaces added so it doesn't become a comment!) but the tag isn't causing a true nextpage, it's just printing as a comment.

    I added it using the add_filter('the_content', 'addNextPageBL'); hook. My guess is I need to somehow hook earlier in the processing.

    Any ideas what hook I should use?

  2. westpointer
    Member
    Posted 6 years ago #

    BTW - here is what the plugin looks like. Right now it adds <!--nextpage --> after the third ending paragraph tag.

    <?php
    
    function addNextPageBL($content) {
    	$save = explode('</P>', $content);
    	$content = '';
    	$count = 1;
    	foreach ($save as $a){
    		$content .= $a.'</P>';
    			if ($count == 3){
    				$content .= 'Next Page: <!--nextpage-->';
    			}
    		$count = $count + 1;
    	}
    
    	return $content;
    }
    
    add_filter('the_content', 'addNextPageBL');
    
    ?>
  3. westpointer
    Member
    Posted 6 years ago #

    hehe ... continuing the discussion with myself. I found that nextpage is evaluated in query.php starting around line 1511.

    Before the line if ( preg_match('/<!--nextpage-->/', $content) ) {

    I added this:

    $pos1 = stripos($content, '<!--nextpage-->');
    	if ($pos1 === false) { /* we did not find a nextpage tag so add automatically */
    		$content = str_replace("< /P >", "< /p >", $content);
    		$save = explode('< /p >', $content);
    		$content = '';
    		$count = 1;
    		foreach ($save as $a){
    			$content .= $a.'< /p >';
    				if ($count % 10 == 0){
    					$content .= '<!--nextpage-->';
    				}
    			$count = $count + 1;
    		}
    	}

    The hack first checks if the content contains nextpage tags already. If yes, then nothing is done. If no nextpage tags are found, the hack will insert nextpage after each 10th closing paragraph tag. Wish I could make this a plugin but I don't think there's anywhere to hook to have the right impact.

Topic Closed

This topic has been closed to new replies.

About this Topic