0

I want the to give a little more content after <!--more--> tag inside Loop.

I saw this on wordpress codex

This script gives the content before the <!--more--> tag:

<?php 
global $more;    // Declare global $more (before the loop).
$more = 0;       // Set (inside the loop) to display content above the more tag.
the_content("More...");
?>

This script gives all the content including text below <!--more--> tag:

<?php 
global $more;    // Declare global $more (before the loop).
$more = 1;       // Set (inside the loop) to display all content, including text below more.
the_content();
?>

What I want is:

Post content until <!--more--> tag + a little after (2 lines approx) the <!--more--> tag.

1 Answer 1

0

You can get the diff between your 2 contents and then add to the first one a given number of words like this (not sure, but give it a try ;) ) :

global $more;
$more = 0;
$content_cut = get_the_content( '' );
$more = 1;
$content_full = get_the_content();

// Get the diff
$content_diff = str_replace( $content_cut, '', $content_full );

// Get 10 first words
$some_more_content = wp_trim_words( $content_diff, 10, 'link_more_here' );

// Add it to the end of cut content
$content_cut .= $some_more_content;

echo $content_cut;

The linl_more_here parameter is optionnal and is normaly a tag with the permalink of your current post.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.