How to get_the_content with proper formating inside functions.php?

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.

TL;DR

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

Autor: Dimitar Radev | Modified: June 11, 2019 at 2:55 pm


Leave a Reply

Your email address will not be published. Required fields are marked *

Advertising

Related posts

Change The Color Of Wordpress Admin Dashboard Icon In The Menu

How to change Dash icon color in WordPress admin menu with CSS?

Change the default color for dash icon in the admin menu Probably you have this question when you create a Custom WordPress Theme …

Get current category children

Get current category (taxonomy) children and prepare them for options element.

Today I will share something that I use often. Getting the children of the current queried category or taxonomy and making from them …