Skip to main content
18 votes
Accepted

Removing any and all inline styles from the_content()

If we want to remove all inline styles, then just simply need to add the following code in functions.php. add_filter('the_content', function( $content ){ //--Remove all inline styles-- $...
Reza Mamun's user avatar
12 votes

Change appearance of shortcode text inside editor

You can add a custom plugin, to WordPress and also the TinyMCE visual editor. The follow source is a example that simple works and add a string before and after all shortcode. Usage The shortcode ...
bueltge's user avatar
  • 17.1k
12 votes

Hook added to the_content seems to be called multiple times

I was having the same issue. My the_content filter was being called multiple times and this was slowing down page load as my the_content filter was calling an external API. So in my case, the API was ...
Eric's user avatar
  • 301
11 votes
Accepted

Where to hook into post content?

You can use the_content with an high prioriety (lower number). add_filter( 'the_content', function( $content ) { return 'Hello World '.$content; }, 0); You can even use negative priority: ...
gmazzap's user avatar
  • 46.2k
10 votes
Accepted

Get excerpt from $post->post_content

When in the loop, this will produce excerpt from $post->post_content directly: <?php echo wp_trim_excerpt(); ?> Read more HERE. Alternative Solution: If you are not in the loop, then, you ...
Fayaz's user avatar
  • 8,937
8 votes

Difference between the_content() and get_post()?

post_content is a property of the WP_Post object. WP_Post is an object representing the post data from the database. So post_content contains the raw content as stored in the database. the_content() ...
Jacob Peattie's user avatar
7 votes
Accepted

Hook added to the_content seems to be called multiple times

It is normal for content to be accessed multiple times. For example SEO plugins need to do this to access it and generate meta data from. Also it is a filter hook. Filters should never echo anything ...
Rarst's user avatar
  • 99.7k
6 votes
Accepted

why does the add_action('the_content') overwrite my page

There is a subtle difference between action hooks and filters. The most notable one is that filter functions are expected to receive a value and pass it along in return when done with their work. ...
JHoffmann's user avatar
  • 1,850
5 votes
Accepted

Replace post's "the_content" with ACF value

Instead of updating the post's content, you can filter it using the the_content filter. add_filter( 'the_content', 'wpse241388_use_acf_field' ); function wpse241388_use_acf_field( $content ) { ...
Pat J's user avatar
  • 11.9k
5 votes
Accepted

append code after the_content not working

previous_post_link and next_post_link both output the link directly, which won't work in your case because you're trying to assign the result to a variable. Use get_previous_post_link() and ...
Milo's user avatar
  • 78.5k
5 votes
Accepted

Getting first 20 words without excerpt

Use wp_trim_words() wp_trim_words( get_the_content(), 20 ) As you're outside the main loop wp_trim_words( $recent[ 'post_content' ], 20 ) If you want to apply the same filters as to the_content() ...
Nicolai Grossherr's user avatar
5 votes
Accepted

Add a div of content within the_content after a certain block

Yes, add_filter() is what you're looking for, but to identify a specific block, you want the render_block hook. <?php add_filter('render_block', function($block_content, $block) { // Only for ...
WebElaine's user avatar
  • 9,430
4 votes
Accepted

remove <p> tags from the_content

By default, WordPress adds paragraph tags to category descriptions. Stop this by adding the following to your functions.php file // Remove p tags from category description remove_filter('...
Jodyshop's user avatar
  • 196
4 votes
Accepted

Insert Custom HTML After Shortcode

I wonder if you could override the [rev_slider] with this kind of wrapper: add_shortcode( 'rev_slider', function( $atts = array(), $content = '' ) { $html = ''; // Your custom banner HTML ...
birgire's user avatar
  • 67.4k
4 votes

limit how many words show up in the_content on index

Try wp_trim_words() https://codex.wordpress.org/Function_Reference/wp_trim_words You won't be able to use it with the_content() though because it echoes the content. You'll want to use it with ...
Ian's user avatar
  • 979
4 votes
Accepted

Proper way to use get_the_content() in front-page.php and the content-home.php?

To output your content, It is advised that you pass your content through a filter. get_the_content() does not do this, so it will not for example execute shortcodes or create <p> tags. So, it ...
Johansson's user avatar
  • 15.3k
4 votes
Accepted

How I can split text in the_content() into 2 columns?

Did you try css? <div class="columncontent"> <?php the_content(); ?> </div> Then the css: .columncontent { column-count: 2; } Depending on your theme, you could just ...
rudtek's user avatar
  • 6,143
4 votes
Accepted

$content = $post->post_content; with formating

If i get your question correct, you want the post_content formatted like the content put out by the_content, right? Change your upper code like this: global $post; $content = apply_filters('...
HU is Sebastian's user avatar
4 votes
Accepted

Changing the HTML Of the content

The wrapping <p> is applied by a filter called wpautop. You can disable this filter and wrap the content in your desired wrapper, but it's not really recommended. remove_filter( 'the_content', '...
Johansson's user avatar
  • 15.3k
4 votes
Accepted

Is it possible to change the structure of the HTML generated by the_content()? If yes, how? If not, is there a workaround?

You can use the_content filter, to literally filter the content into your structure. Somthing like this <?php add_filter('the_content',function($the_content){ // find blockquotes $regex =...
David Sword's user avatar
  • 3,337
4 votes
Accepted

the_content() in single-{post-type}.php problem

First of all, you shouldn't use get_posts on your CPT archive - WP already creates a query and selects posts that should be display in there. So your archive-pjesma.php should look like this: <?...
Krzysiek Dróżdż's user avatar
4 votes
Accepted

Filter Gutenberg Blocks Content

Have you tried using parse_blocks() (pass in get_the_content())? That returns an array of all the blocks in your content. From there you can pull out block names and id attributes using an array map ...
Mattimator's user avatar
4 votes
Accepted

How can I show the actual content of Posts page because the_content() is showing all blog content?

You can use: get_queried_object_id() to get the ID of the static posts Page. Alternatively, you may also use get_option( 'page_for_posts' ). $post_id = get_queried_object_id(); //$post_id = ...
Sally CJ's user avatar
  • 39.3k
4 votes
Accepted

the_content filter - checking the post

You'll need to rely on the global post variable, or get_post(), which is essentially the same thing. add_filter( 'the_content', function( $content ) { $post = get_post(); if ( ...
Jacob Peattie's user avatar
3 votes
Accepted

Change Content for Specific Page

Your function is signup but you're hooking check_for_signup. You're also trying to apply the_content filters from within a function that's hooked to the_content: function ...
TheDeadMedic's user avatar
  • 36.4k
3 votes

Apply the_content filter for specific post types only

Whenever the_content is called, there is a global WP_Post object. So you can look into that to find its post type: if ( ! in_array( get_post()->post_type, [ 'tool', 'article' ] ) ) return $...
fuxia's user avatar
  • 107k
3 votes

Split Content and Gallery

It should not be sooo complicated. The code below can be shortened down to a couple of lines at wish. Approach 1. Get the clean post content by removing all shortcodes, including the gallery one from ...
bob-12345's user avatar
  • 151
3 votes

How can i remove all html tags from get_the_content()?

This removes both <htmltags> and <!-- comments -->: echo wp_strip_all_tags( get_the_content() ); wp_filter_nohtml_kses() didn't get me rid of the comments. seen here
Fanky's user avatar
  • 317
3 votes
Accepted

How to ensure "the_content" filter runs only for the main displayed content?

According to Wordpress documentation, you can accomplish this using this code: add_filter( 'the_content', 'filter_the_content_in_the_main_loop' ); function filter_the_content_in_the_main_loop( $...
Stephen M. Harris's user avatar
3 votes
Accepted

Cannot retieve the_content() and the_author() - both returning empty strings

get_the_content and the_author have to be in a loop so you would need to use other functions to get the content you need global $wp_query; $post = $wp_query->post; $page_id = $post->ID; // page ...
Gareth Gillman's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible