Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Display the Featured Image after the first paragraph in WordPress
<?php get_header(); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h1><?php the_title(); ?></h1>
$after_p_img = 1;
$content = apply_filters('the_content', $post->post_content);
if(substr_count($content, '<p>') > $after_p_img){
$contents = explode("</p>", $content);
$p_count = 1;
foreach($contents as $content){
echo $content;
if($p_count == $after_p_img){
if ( has_post_thumbnail() ) {
echo "</p>";
<?php the_content(); ?>
<?php endwhile; endif; ?>
<?php get_footer(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.