Last active
July 28, 2017 09:55
-
-
Save ThijsFeryn/945d904d14458d8f16d6d78d732727fd to your computer and use it in GitHub Desktop.
Logic do add the date to the post of blauwzwartfans.be
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
function addDateBeforeFirstParagraph($content) { | |
if(!is_singular('post')) return $content; | |
$closing_p = '<p>'; | |
$paragraphs = explode( $closing_p, $content ); | |
foreach ($paragraphs as $index => $paragraph) { | |
if ( trim( $paragraph ) ) { | |
$paragraphs[$index] .= $closing_p; | |
} | |
if ($index == 2) { | |
$paragraphs[$index] = '<span>'.get_the_date('d F Y H:i').' - </span>'.$paragraphs[$index]; | |
} | |
} | |
return implode( '', $paragraphs ); | |
} | |
add_filter( 'the_content', 'addDateBeforeFirstParagraph' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment