[Resolved] Reading Time Dynamic Field in Post Meta

Home Forums Support [Resolved] Reading Time Dynamic Field in Post Meta

Home Forums Support Reading Time Dynamic Field in Post Meta

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #2202678
    Puneet

    Hi
    I am using Post meta as the image below.

    https://snipboard.io/cZ62oA.jpg

    post link: https://manoftech.com/wordpress-com-review/

    I just need to add reading time to it. I used the filter below given by Tom from another post.

    `

      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 );

      return $time . ‘ minutes’;
      }

      add_filter( ‘generate_post_date_output’, function( $output ) {
      $output .= ‘

      Reading time: ‘ . tu_estimated_reading_time() . ‘

      ‘;

      return $output;
      } );

    The question is, how do I add reading time to the post meta designed using the dynamic option in elements via generateblocks?

    Regards,
    Puneet

    #2202684
    David
    Staff
    Customer Support

    Hi there,

    see this topic – it provides the same thing but as a shortcode:

    https://generatepress.com/forums/topic/how-to-move-an-element-below-a-certain-element/#post-2123998

    Look for this line:

    $time ='<div class="read-time"><span class="gp-icon">•</span>Reading time: '. ceil( $word_count / $wpm ) . ' minutes'. '</div>';

    Change that to:

    $time ='Reading time: '. ceil( $word_count / $wpm ) . ' minutes';

    #2202706
    Puneet

    It’s showing with a shortcode, but how do I control the padding around it within generateblocks element. I would need a bit of padding on the left.

    #2202714
    David
    Staff
    Customer Support

    Add the shortcode inside of a GB Headline Block, the output from the shortcode will respect the headline blocks styles

    #2202718
    Puneet

    Hi David,
    Thanks again. It worked perfectly. Though I wonder why I couldn’t think of that…lol. I have a lot to learn clearly. Thanks a ton again.

    Regards,
    Puneet

    #2202720
    David
    Staff
    Customer Support
    #2202740
    Puneet

    Oops,
    Sorry, I forgot to ask another query. If I add social icons from the generateblocks template library, what URL do I add to them to make them social share icons and not follow buttons? We can use Facebook and Twitter as an example here. Thanks,

    Regards,
    Puneet

    #2202748
    David
    Staff
    Customer Support

    Unfortunately thats not possible. You would need to use a social sharing plugin for that.

    #2202765
    Puneet

    I am using a social sharing plugin. I was thinking of adding a custom button near the featured image or with the post meta. Something like this:-

    https://snipboard.io/9j7g45.jpg

    I can place the icons but don’t know how to use them as share buttons.

    Regards,
    Puneet

    #2202769
    David
    Staff
    Customer Support

    The Icons added by a GB Button or Headline block can only link to static URLs, they can’t be converted to social shares without hijacking them with some Javsascript which is out of our scope.

    Just add your social share icons using the plugin shortcode – if need be i can help with some CSS to position them

    #2202771
    Puneet

    Thanks David,
    Probably get to it later. Thanks again,

    Regards,
    Puneet

    #2202779
    David
    Staff
    Customer Support
Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.