Skip to content

Instantly share code, notes, and snippets.

@ThijsFeryn ThijsFeryn/bzf.php
Last active Jul 28, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.