Add "Posted on" to post date

How can I add the words "Posted on" before the post data in a Twentyfourteen theme's post? The default is only to show the date and clock icon.

I'm not sure if this is a basic modification or if it's going to be a fix unique to Twentyfourteen.

I found this web page talking about removing the "posted on" text in the Twentyeleven theme (I hoped the themes would be similar). It said to look in the functions.php file for function twentyeleven_posted_on() but I was unable to find anything like that in the Twentyfourteen parent theme's functions.php file. There didn't seem to be anything directly relating to a post's date in the Twentyfourteen functions.php file.

I am using a child theme, so I assume I'm probably going to be putting an altered function in my child theme's functions.php file, but I can't find the original function in Twentfourteen.

The reason I ask is because Twentyfourteen default of only having the date has confused some of my readers; when the post is talking about an event they think the post date is the date of the event.

Solution (Thanks to Tom Woodward and Dave Clements)

Both Tom's and Dave's functions worked, but neither of them did at first because I was placing the new function below the ? which is the ending tag for PHP and no code would work below it.

This was my existing child theme's functions.php file (just basically copied from the Wordpress support guide on setting up a child theme)

?php
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}

?

I needed to add the new function in between the last } and the bottom ?

?php
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}

function add_publish_dates( $the_date, $d, $post ) {
if ( is_int( $post) ) {
$post_id = $post;
} else {
$post_id = $post-ID;
}

return 'Posted on '. date( 'Y-d-m - h:j:s', strtotime( $the_date ) );
}
add_action( 'get_the_date', 'add_publish_dates', 10, 3 );

?

I eventually ended up using Tom Woodward's code because it placed the little clock icon before the "Posted on" whereas Dave Clement's put it after "Posted on" in between it and the date, which looked odd.

Then I changed the date formatting for the date after return 'Posted on '. date from 'Y-d-m - h:j:s' (which displayed the date as 2016-16-03 - 12:00:00 [which oddly ALWAYS said it was posted at 12am, when the posts were not]) to 'F j, Y' (Which displays the default "March 16, 2016")

?php
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}

function add_publish_dates( $the_date, $d, $post ) {
if ( is_int( $post) ) {
$post_id = $post;
} else {
$post_id = $post-ID;
}

return 'Posted on '. date( 'F j, Y', strtotime( $the_date ) );
}
add_action( 'get_the_date', 'add_publish_dates', 10, 3 );

?

As I said, I ended up using Tom Woodward's code as a base, but Dave Clements code did exactly what I had asked (just not exactly what I wanted) and he solved the ? problem for me, so I give Dave the point. But thank you so much to both Tom and Dave!

Topic theme-twenty-fourteen date posts Wordpress

Category Web


The post date is added by twentyfourteen_posted_on as shown in content.php. This function is in /inc/template-tags.php and is correctly wrapped in an if ( ! function_exists( 'twentyfourteen_posted_on' ) ) conditional so you can declare the same function in your child theme and modify it to your heart's content.

As such you could add a function like this to your theme's functions.php file and that should do the trick (note the addition of "Posted on " in the printf function:

function twentyfourteen_posted_on() {
        if ( is_sticky() && is_home() && ! is_paged() ) {
                echo '<span class="featured-post">' . __( 'Sticky', 'twentyfourteen' ) . '</span>';
        }

        // Set up and print post meta information.
        printf( 'Posted on <span class="entry-date"><a href="%1$s" rel="bookmark"><time class="entry-date" datetime="%2$s">%3$s</time></a></span> <span class="byline"><span class="author vcard"><a class="url fn n" href="%4$s" rel="author">%5$s</a></span></span>',
                esc_url( get_permalink() ),
                esc_attr( get_the_date( 'c' ) ),
                esc_html( get_the_date() ),
                esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
                get_the_author()
        );
}

I took a look at the documentation here and this filter seems to work for 2014.

function add_publish_dates( $the_date, $d, $post ) {
if ( is_int( $post) ) {
    $post_id = $post;
} else {
    $post_id = $post->ID;
}

return 'Posted on '. date( 'Y-d-m - h:j:s', strtotime( $the_date ) );
}
add_action( 'get_the_date', 'add_publish_dates', 10, 3 );

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.