Skip to content

Instantly share code, notes, and snippets.

@derekshirk
Last active August 29, 2015 14:03
Show Gist options
  • Save derekshirk/25450da592aafde62f71 to your computer and use it in GitHub Desktop.
Save derekshirk/25450da592aafde62f71 to your computer and use it in GitHub Desktop.
WordPress - Split content Before & After The More Tag
<?php
while( have_posts() ) : the_post();
$content_parts = get_extended( get_the_content() );
echo '<h1 class="post-title">' . get_the_title() . '</h1>';
echo '<p class="intro">' . $content_parts['main'] . '</p>';
echo '<!-- Paste your ad code here. -->';
echo '<div class="article">' . $content_parts['extended'] . '</div>';
endwhile;
?>
@derekshirk
Copy link
Author

This might be my favorite among all these gems: The get_extended() function allows us to literally split the two parts, before and after the tag.

Usage
The usage is pretty simple, too. Let's say that you're in the single.php file and you're going to display an ad between the intro and the rest of the article. Here's how you do The Loop:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment