Skip to content

Instantly share code, notes, and snippets.

@KoolPal
Forked from c-askew/Posted On - Byline
Created March 17, 2020 12:49
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 KoolPal/3ab2ced327ff48c3a417edd3ee3ab62d to your computer and use it in GitHub Desktop.
Save KoolPal/3ab2ced327ff48c3a417edd3ee3ab62d to your computer and use it in GitHub Desktop.
PHP Functions to add to Function.php to make various element contents easily edittable with CSS. Included so far - > Blog Posts "Posted On" & "Byline" - Edit inside post-pre / byline-pre spans
if ( ! function_exists( 'flatsome_posted_on' ) ) :
// Prints HTML with meta information for the current post-date/time and author.
function flatsome_posted_on() {
$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
}
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() ),
esc_attr( get_the_modified_date( 'c' ) ),
esc_html( get_the_modified_date() )
);
$posted_on = sprintf(
'<span class="post-pre">Posted on </span>' . esc_html_x( '%s', 'post date', 'flatsome' ),
'<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
);
$byline = sprintf(
'<span class="byline-pre">by </span>' . esc_html_x( '%s', 'post author', 'flatsome' ),
'<span class="meta-author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>'
);
echo '<span class="posted-on">' . $posted_on . '</span><span class="byline"> ' . $byline . '</span>';
}
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment