Skip to content

Instantly share code, notes, and snippets.

@ThijsFeryn
Last active July 28, 2017 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThijsFeryn/945d904d14458d8f16d6d78d732727fd to your computer and use it in GitHub Desktop.
Save ThijsFeryn/945d904d14458d8f16d6d78d732727fd to your computer and use it in GitHub Desktop.
Logic do add the date to the post of blauwzwartfans.be
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