Site logo

Archived topic

Adding icon to metadata

7 replies · Started by manaadiar on November 29, 2021

Viewing posts 1–8 of 8

Hi, I would like to know how to add a "clock" icon to the left the "reading time" meta data in the meta box, like the calendar and data icon (see screenshot).. Pls will you let me know the code.. Thanks..

Icon

Hi there,

what code have you used to add the Reading time ?

Hi David, below, added to function.php in GP Child theme..

// Code to add reading time

function reading_time() {
$content = get_post_field( 'post_content', $post->ID );
$word_count = str_word_count( strip_tags( $content ) );
$readingtime = ceil($word_count / 200);

if ($readingtime == 1) {
$timer = " minute";
} else {
$timer = " minutes";
}
$totalreadingtime = $readingtime . $timer;

return $totalreadingtime;
}

Hi there,

Try change the return $totalreadingtime to return "<span class=reading-time>" . $totalreadingtime . "</span>".

Then we should be able to add this CSS if you are using font awesome plugin:

span.reading-time:before {
    content: "\f017";
    font-family: 'Font Awesome 5 Free';
}

Let me know if this helps :)

Am not using the fontawesome plugin.. But I updated the code and it is working.. Only problem is that there is no space between the icon and the reading time.. How do I change this code to add the space..??

time icon

add_action( 'generate_post_meta_items', function( $item ) {
if ( 'reading-time' === $item ) {
echo reading_time();
}
}

You can add margin to the icon using CSS:

span.reading-time:before {
    content: "\f017";
    font-family: 'Font Awesome 5 Free';
    margin-right: 0.6em;
}

Perfect.. Thanks..

You are welcome :)

This archived topic is closed to new replies.