Archived topic
Post Visit Counter and Mins Read time
42 replies · Started by Sourabh on December 3, 2020
for more information, you can also refer snap -
https://www.dropbox.com/s/g4ssatjc8ofcksf/read%20mins%20time%20snap.png?dl=0
Also, let me know what is that "float" above reading time mins ??
Can you try this code, instead?: https://generatepress.com/forums/topic/how-can-additional-content-be-included-in-each-grid-post-on-the-home-page/#post-1241829
No, It seems worse, refer below -
https://www.dropbox.com/s/wsp4pf4jeuo6668/read%20mins%20css%202nd.png?dl=0
Regds:
Here's the complete code:
function tu_estimated_reading_time() {
$post = get_post();
$content = $post->post_content;
$wpm = 300; // How many words per minute.
$clean_content = strip_shortcodes( $content );
$clean_content = strip_tags( $clean_content );
$word_count = str_word_count( $clean_content );
$time = ceil( $word_count / $wpm );
if ($time == 1) {
return $time . ' minute';
} else {
return $time . ' minutes';
}
}
add_filter( 'generate_post_author_output', function( $output ) {
$output .= '<div class="read-time">Reading time: ' . tu_estimated_reading_time() . '</div>';
return $output;
} );
Hi Tom,
It seems working, Looking like below -
https://www.dropbox.com/s/ufwvmpbiu5gcvb6/Meta%20Reading%20%20time.png?dl=0
can you help me to set it in a format in a row -
Like
Author By: | Date | Comments | Reading Time etc...
(Good if also getting one line up and one line down, it's like two lines box), give a CSS for arranging this.
Give this a shot:
.read-time {
display: inline-block;
border-left: 1px solid #ddd;
padding-left: 5px;
margin-left: 3px;
}
Hi Thanks Tom,
Above CSS worked only for reading time (As all in a row now), thanks for that, But I requested CSS for the entire Meta Like below format-
Author By: | Date | Comments | Reading Time | …
(Good if also getting one line up and one line down, it’s like two lines box), give a CSS for arranging this.
Help if you can please.
There seems to be an error on your website when trying to view a single post at the moment.
You can see how to re-order/add to your post meta items here: https://docs.generatepress.com/article/generate_header_entry_meta_items/
Yes Tom,
My site is broken again, It's happening because of the child theme, Don't know whats wrong, (I have raised a separate ticket for my child theme concern), Please review that, so that i will restore it again from backup...
however a meta is a concern, I have already read this article it's about metadata, however, I requested custom CSS for the entire Meta display in the below format-
Author By: | Date | Comments | Reading Time | …
(Good if also getting one line up and one line down, it’s like two lines box), give a CSS for arranging this.
https://www.dropbox.com/s/rc7251uh61goazx/Meta%20below%20title.png?dl=0
Let's figure out the error first, then we can re-open this one and provide some CSS.
Yes I like your decision..
HI Tom,
the issue has been resolved so Let's finish this topic and give me CSS for the below -
Author By: | Date | Comments | Reading Time | …
(Good if also getting one line up and one line down, it’s like two lines box), give a CSS for arranging this.
We'll need to change it up to rearrange where the reading time goes. This is the updated code:
function tu_estimated_reading_time() {
$post = get_post();
$content = $post->post_content;
$wpm = 300; // How many words per minute.
$clean_content = strip_shortcodes( $content );
$clean_content = strip_tags( $clean_content );
$word_count = str_word_count( $clean_content );
$time = ceil( $word_count / $wpm );
if ($time == 1) {
return $time . ' minute';
} else {
return $time . ' minutes';
}
}
add_action( 'generate_post_meta_items', function( $item ) {
if ( 'reading-time' === $item ) {
echo '<span class="reading-time">Reading time: ' . tu_estimated_reading_time() . '</span>';
}
} );
add_filter( 'generate_header_entry_meta_items', function() {
return array(
'author',
'date',
'comments-link',
'reading-time',
);
} );
add_action( 'wp', function() {
if ( is_single() ) {
add_filter( 'generate_show_comments', '__return_true' );
}
} );
More info on this method here: https://docs.generatepress.com/article/generate_header_entry_meta_items/
As for the lines, try this:
.entry-header .entry-meta {
border-top: 1px solid #000;
border-bottom: 1px solid #000;
padding: 5px 0;
margin-top: 10px;
}
Nah, Something went wrong seems -
Tom, Reading time + Comments section is not visible now, they vanished post updating the code, should i jump to the previous one ??
I think I have a few codes which Leo has given to me previously as below -
add_action( 'wp', function() {
if ( is_single() ) {
add_filter( 'generate_show_comments', '__return_true' );
}
} );
add_filter( 'generate_header_entry_meta_items', function() {
return array(
'categories',
'date',
'author',
);
} );
However, when I delete these codes from the child theme then to it's looking like this (Refer private section),
Guide me on what to do now from here ..
I've adjusted the functions here: https://generatepress.com/forums/topic/post-visit-counter-and-mins-read-time/page/2/#post-1586449
Make sure those are the only post meta related functions you have active on your site - backup and then remove the others.