Split Post Loop into two loops, issue with post-thumbnail

I need to split the loop of each post into two loops.

The first paragraph will be the first element, the second contains the rest of the content (without the first paragraph).

So this is working fine: https://wordpress.stackexchange.com/a/145879/181889

functions.php (from the link above):

function get_first_paragraph(){
global $post;
$str = wpautop( get_the_content() );
$str = substr( $str, 0, strpos( $str, ‘</p>’ ) + 4 );
$str = strip_tags($str, ‘<a><strong><em>’);
return ‘<p>’ . $str . ‘</p>’;

function get_the_post(){
global $post;
$str = wpautop( get_the_content() );
$str = substr( $str, (strpos( $str, ‘</p>’)));
return $str;

single.php (content-single.php):

<div class=”col”><?php echo get_first_paragraph(); ?></div>
<div class=”col”><?php echo get_the_post(); ?></div>

In addition to this, I need the ability to add the post-thumbnail via a shortcode into the post.

I am using this: https://wordpress.stackexchange.com/a/213769

So I’ve added this into functions.php:

function thumbnail_with_caption_shortcode($atts) {
global $post;

// Image to display

$thumbnail = get_the_post_thumbnail($post->ID);

// ID of featured image

$thumbnail_id = get_post_thumbnail_id();

// Caption from featured image’s WP_Post

$caption = get_post($thumbnail_id)->post_excerpt;

// Link to attachment page

$link = get_permalink($thumbnail_id);

// Final output

return ‘<div class=”featured-image”>’
. ‘<a href=”‘ . $link . ‘”>’
. $thumbnail
. ‘<span class=”caption”>’ . $caption . ‘</span>’
. ‘</a>’
. ‘</div>’;
add_shortcode(‘thumbnail’, ‘thumbnail_with_caption_shortcode’);

The issue is, that the [thumbnail] shortcode is not working in combination with the paragraph-functions. I am only seeing [thumbail] in the output.

Since my php knowledge is limited, any ideas how to fix this?

Read more here:: Split Post Loop into two loops, issue with post-thumbnail

Leave a Reply

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