How to get the_content with all HTML tags inside functions.php?
To get the post or page content inside WordPress functions.php with all the HTML tags you need to use the_content filter.
This method of getting the content data is very helpful when creating custom REST API points or Plugins.
$my_variable = apply_filters('the_content', get_post_field('post_content', $post->id));
You have probably landed here after browsing the WEB for “get_the_content() is not formated properly” or something similar. The reason is that get_the_content() is not passed
through the ‘the_content‘ filter. Wich means that $my_variable = apply_filters(‘the_content’, get_the_content($post->id)); will work as well. The reason I’m using get_post_field(‘post_content’, $post->id) is because sometimes in get_the_content() and the_content() functions a variable sent to a PHP count() could be NULL and that is an issue for PHP 7.2
Today I will share something that I use often. Getting the children of the current queried category or taxonomy and making from them …
Looking to fix this “Warning: count(): Parameter must be an array or an object that implements Countable in /wp-includes/post-template.php on line 284” or …
Wordpress Resources | Snippets | Themes
- How to create simple WordPress Loop for posts and display it in single.php
- How to quickly install Roots Trellis and Bedrock for local development environment on Windows
- What do you need to install on your Windows PC for work with Roots Trellis and Bedrock stack.
- Ctreate a query from a single category slug
- How to add HTML elements to Contact Form 7 (Select Multiple)