[Resolved] How can additional content be included in each grid (post) on the home page?

Home Forums Support [Resolved] How can additional content be included in each grid (post) on the home page?

Home Forums Support How can additional content be included in each grid (post) on the home page?

  • This topic has 19 replies, 3 voices, and was last updated 4 years ago by David.
Viewing 5 posts - 16 through 20 (of 20 total)
  • Author
    Posts
  • #1246224
    David
    Staff
    Customer Support

    There isn’t a template tag to call custom functions.

    #1246242
    Anonymous

    Thanks David. What options are there to call a custom function in “Elements”?

    #1246420
    David
    Staff
    Customer Support

    Header Elements doesn’t accept PHP ( unlike Hooks ) but they will accept shortcodes.
    See this topic for creating a shortcode function:

    https://generatepress.com/forums/topic/need-some-help-in-designing-header/#post-1048701

    #1247012
    Anonymous

    Thanks David.

    I am assuming that the example code below has to be added to the functions.php file.

    If yes, the shortcode, {{reading-time}}, in the header element doesn’t return a value but rather displays {{reading-time}} verbatim.

    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;
    }
    
    add_shortcode('reading-time', 'tu_estimated_reading_time');
    #1247197
    David
    Staff
    Customer Support

    Yes, in functions.php
    And you would add this to your header elements content: [reading-time]

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