Archived topic
Help with function
2 replies · Started by epickenyan on February 27, 2019
Hi Tom. I want to show this <div class="reading-time">Time To Read: <?php echo reading_time(); ?><div> next to the byline on single posts (and then float it right with CSS). Would you kindly help me with a function to do that? I want them to appear on a straight line because using the element after entry title does not help and I had to adjust the top margin using CSS which looks out of line on minimal devices.
Here is the reading time function.
function reading_time() {
$content = get_post_field( 'post_content', $post->ID );
$word_count = str_word_count( strip_tags( $content ) );
$readingtime = ceil($word_count / 250);
if ($readingtime == 1) {
$timer = " minute";
} else {
$timer = " minutes";
}
$totalreadingtime = $readingtime . $timer;
return $totalreadingtime;
Hi there,
try this CSS:
.single-post .inside-article .entry-meta, .single-post .reading-time {
display: inline-flex;
}
.single .byline {
margin-left: 0.5em;
}
Then in your .reading-time CSS you can remove the float and add a margin-top: 0.5em;
Hi. That inline-flex code is making my category, tags and navigation meta below posts to be broken. How to target only the meta at the top of the post?
Solved footer.entry-meta {display:inline-block!important;}