Site logo

[Resolved] Post Visit Counter and Mins Read time

Home Forums Support [Resolved] Post Visit Counter and Mins Read time

Home Forums Support Post Visit Counter and Mins Read time

Viewing 15 posts - 16 through 30 (of 43 total)
  • Author
    Posts
  • #1574044
    Sourabh

    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 ??

    #1574739
    Tom
    Lead Developer
    Lead Developer
    #1574751
    Sourabh
    #1574756
    Tom
    Lead Developer
    Lead Developer

    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;
    } );
    #1574768
    Sourabh

    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.

    #1575231
    Tom
    Lead Developer
    Lead Developer

    Give this a shot:

    .read-time {
        display: inline-block;
        border-left: 1px solid #ddd;
        padding-left: 5px;
        margin-left: 3px;
    }
    #1575546
    Sourabh

    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.

    #1576524
    Tom
    Lead Developer
    Lead Developer

    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/

    #1577480
    Sourabh

    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

    #1577762
    Tom
    Lead Developer
    Lead Developer

    Let’s figure out the error first, then we can re-open this one and provide some CSS.

    #1577778
    Sourabh

    Yes I like your decision..

    #1586047
    Sourabh

    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.

    #1586449
    Tom
    Lead Developer
    Lead Developer

    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;
    }
    #1586757
    Sourabh

    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 ..

    #1587444
    Tom
    Lead Developer
    Lead Developer

    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.

Viewing 15 posts - 16 through 30 (of 43 total)
  • You must be logged in to reply to this topic.