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
There isn't a template tag to call custom functions.
Thanks David. What options are there to call a custom function in "Elements"?
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
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]