I believe that’s telling you that $post
(in $post->ID
) is undefined. Try this instead:
function sh_reading_time() {
$content = get_post_field( 'post_content', get_the_ID() );
$word_count = str_word_count( strip_tags( $content ) );
$readingtime = ceil($word_count / 200);
if ($readingtime == 1) {
$timer = " minute";
} else {
$timer = " minutes";
}
$totalreadingtime = $readingtime . $timer;
return $totalreadingtime ;
}
Related Posts:
- Best way of passing PHP variable between partials?
- Custom page with variables in url. Nice url with add_rewrite_rule
- Difference between the_content() and get_post()?
- Insert Ad Code in the Middle of a Post
- How Can I Access a PHP Variable in Another PHP Function
- get_the_excerpt() not returning anything when post has no excerpt
- Function to wrap the_content in a div
- Function to show only first instance of shortcode
- Automatically insert php function into post $the_content
- Is it better to assign functions like get_the_id() to a variable if it’s used multiple times?
- Searching for content post
- str_replace function in theme
- Adding HTML to the end of every post with the Block Editor
- Inserting a functions output after the content
- Add caption functionality to custom WordPress theme
- Assigning WP functions which echo to PHP variables
- Passing values from a widget to a function within a plugin
- Removing permalink from post thumb in twentyeleven
- Using $themename Variables
- How to pass variables from a function in functions.php to an other one
- Add Element as a Filter to the_content
- Insert template-part inside the content
- Define PHP variable from a seperate API if statement
- Remove links from the_content when using filters wp_trim_excerpt
- problem loading stylesheets to wp_head dynamically
- How do I pull excerpts from pages?
- does wp function the_content(); accept another tag inside
- How to remove a specific word at the beginning of the content and add it to the end of the content
- The_content and Preg_replace in loaded Iframe [closed]
- first paragraph of the_content as meta description
- Changing where my author box is printed
- Insert Content Before div#main from the functions.php File
- If is_single in functions.php
- add_menu_page() with variable function
- Conditional function for excluding first image from content, not working
- Do I Need to Prefix Variables Inside Functions?
- Updating custom query var with multiple values
- Change Page Title
- get variables data from functions.php to template wordpress (without global variables)
- Getting value of variable from functions.php and debugging it
- Pass post ID from archive template to functions file
- How to access custom class methods from any include without using global
- Strip all HTML tags from product content and resave
- Remove External Links from WordPress posts Using add_filter() in Theme functions.php
- $content is empty while using DOMDocument
- Using a variable in name of dynamically-called helper function
- Add array of category IDs to global variable?
- Shortcode to eliminate and replace with
- Setting a cookie in functions.php and it gets deleted when working on an other function
- getExcerpt: Make ellipsis appear only if character limit is reached
- Function the_content
- How accomplish modification the_content if home/start page?
- Using Output from one Function and calling it into another
- How do I access variables outside a function [closed]
- Trying to get this function to show below the content
- add variable to actions/functions across different files (woocommerce)
- Creating mixture of shortcodes to use in the visual/text editor
- How I can show short content with short tag
- Missing feature image link function
- What’s the difference between home_url() and site_url()
- Remove “Category:”, “Tag:”, “Author:” from the_archive_title
- get_template_directory_uri pointing to parent theme not child theme
- How to customize the_archive_title()?
- remove empty paragraphs from the_content?
- What is the “with_front” rewrite key?
- Why use if function_exists?
- How to override parent functions in child themes?
- wp_enqueue_script was called incorrectly
- Add multiple custom fields to the general settings page
- Ajax call always returns 0
- 400 bad request on admin-ajax.php only using wp_enqueue_scripts action hook
- How long does a deprecated function live in core?
- Solution to render Shortcodes in Admin Editor
- How to add a data attribute to a WordPress menu item
- What’s the difference between esc_html, esc_attr, esc_html_e, and so on?
- remove_action on after_setup_theme not working from child theme
- plugins_url vs plugin_dir_url
- Remove type attribute from script and style tags added by WordPress
- How to run a function every 5 minutes?
- Upload Multiple Files With media_handle_upload
- How to display custom field in woocommerce orders in admin panel?
- Adding fields to the “Add New User” screen in the dashboard
- Issues with title-tag and document_title_parts
- How do I get the current edit page ID in the admin?
- How to check if a user exists by a given id
- Why isn’t is_page working when I put it in the functions.php file?
- Add tags to the section via functions.php
- Add image size if page template
- How to create a custom order status in woocommerce!
- Remove Actions/Filters added via Anonymous Functions
- Adding a second email address to a completed order in WooCommerce [closed]
- How to load parent_theme functions.php before child_theme?
- How to load scripts/styles specific for a page
- Programatically add options to “add new” custom field dropdown
- Is there any global functions.php file which works for any theme?
- Excluding iPad from wp_is_mobile
- When should you, and when should you not, use wp_list_pluck()?
- Get the ID of the page a menu item links to?
- Add container to nav_menu sub menu
- Difference between the_permalink() and get_permalink() function