Site logo

Archived topic

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

19 replies · Started by Former User on April 13, 2020

Viewing posts 16–20 of 20

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

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

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

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

This archived topic is closed to new replies.