How do you add text after displaying the post date for wordpress?

Currently, I have the following code that hooks when the date is displayed. I want this to code to effect dates on listed posts (index.php) and a single post.

function rating_after_date()
{
return printf(
     'Ratings: %s'
    ,get_post_meta( get_the_ID(), 'post_rating', true )
);

}
add_action( 'get_the_date', 'rating_after_date' );

It changes the date but not the way I want it to:

Read More
Ratings: 0Ratings: 010

I would like the posts to the display the date like:

March 22, 2016 | Rating: <somenumber>

Thanks for any help.

Related posts

1 comment

  1. That filter takes in parameter the date, date format and post id.
    You could do something like this :

    function rating_after_date($date, $d, $post_id)
    {
        return $date . printf(' | Ratings: %s'
                     ,get_post_meta( get_the_ID(), 'post_rating', true )
    );
    
    add_action( 'get_the_date', 'rating_after_date' );
    

    Mote that you should adjust the priority of your new filter so that it executes at the end of the stack.

    Here is a good example : https://codex.wordpress.org/Plugin_API/Filter_Reference/get_the_date

Comments are closed.