JavaScript for WordPress Forums Gutenberg Development wpautop behavior for dynamic blocks

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
  • #76378

    I’m creating some custom dynamic blocks for WordPress Gutenberg editor

    I use the PHP render for these blocks, meaning I have this code on save:

    save: function( props ) {
    // Rendering in PHP


    The render function is called via this callback:

    register_block_type( ‘my-plugin/latest-post’, array(
    ‘render_callback’ => ‘my_plugin_render_block_latest_post’,
    ) );
    I’m not gonna post the function code since is irrelevant in this case. (I do a WP_Query and display some custom post data and return a html code),

    Gutenberg takes the output from the function and adds <p> and <br> tags (classic wpautop behaviour) and mess up the block.
    Is this normal?
    Is there any solution beside remove_filter( ‘the_content’, ‘wpautop’ ); ?

    Thank you for any input.

    Zac Gordon

    Hi there! Not sure exactly where this is being called. In our example we return markup and nothing extra is added or filtered. If you just return something hardcoded in your function does the same thing happen? Trying to determine exactly where this behavior is triggered.


    Let me some tests with hard coded html and will get back to you.


    The same html markup but hard coded is displayed correct. The php generated markup is not . Looking at my php function i think that. myabe, using the ob_start() and ob_get_contents php function could be the problem. This is the code that generated the output.

            while ($recent_posts->have_posts()): $recent_posts->the_post();
                if($type == 'estate_property'){
                } else {
                    if(isset($attributes['align']) && $attributes['align']=='horizontal'){
            $templates = ob_get_contents();

    🙂 i think i found it, It happens in your 12-dynamic example also.(maybe you can confirm it for me )

    If you use get_the_excerpt() (and i think get_the_content() also ) it will trigger the wpautop filter.

    For ex

    foreach ( $recent_posts as $post ) {
    		$post_id  = $post['ID'];
    		$markup  .= get_the_excerpt($post_id).sprintf(
                            <a href="%1$s">%2$s</a>
    			esc_url( get_permalink( $post_id ) ),
    			esc_html( get_the_title( $post_id ) )

    Here is a screenshot

    Can you confirm my findings ? Thank you

    Zac Gordon

    Yup, this makes sense to me that this would be happening anytime you went to get content where that filter gets applied.


    So, is this a bug or expected behavior ? Any solutions for this situation -( removing the filter is not acceptable on places like themeforest ).
    Thank you for your help.

    Zac Gordon

    If I understand the issue correctly it sounds like you’re getting content and that content has filters applied that you don’t want correct? Specifically wpautop.

    I guess so that I can better understand what it is that you are trying to do, why don’t you want the wpautop filter applied? If you really don’t want the filter my two first guesses are you can get the content pre being filtered with the REST API context “edit” and content.raw. However, not sure that’s what you want either.

    The other option would be to just remove that filter in the one instance where you are calling it. I’m not sure exactly what conditional check would work here, but that would be the second approach.

    Without seeing the code or understanding what you’re trying to do specifically, I’m just kind of guessing here. Sorry if I’m still not understanding the issue..

    Let me know!


    I’m doing the plugin for ThemeForrest and in their guidelines they ask to not remove the wpautop filter. The guys that will do the review are not gonna investigate too much the problem – they will just reject it. That’s why i was trying to not use this solution. The alternative will be to use get_post_field( 'post_excerpt',..) and see if the Gutenberg team will consider this a issue or not.

    Thank you again for taking the time to look over this.

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.