Last active
August 29, 2015 14:03
-
-
Save derekshirk/25450da592aafde62f71 to your computer and use it in GitHub Desktop.
WordPress - Split content Before & After The More Tag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: