• Resolved Jos Velasco

    (@josvelasco)


    I’m using this function to append blocks to the_content:

    function filter_the_content( $content ) {
    	
    	$header = $get_block = get_post( 1570 );
    	$header = $get_block->post_content;
    	
    	$footer = $get_block = get_post( 1586 );
    	$footer = $get_block->post_content;	
    	
    	$content = $header . $content . $footer;
    
    	return $content;
    }
    add_filter( 'the_content', 'filter_the_content' );

    If the block I’m calling is a reusable block that has blocks inside, the $get_block->post_content returns as:
    <!– wp:block {“ref”:1567} /–>
    <!– wp:block {“ref”:1568} /–>

    How can I make it recursive so it prints the actual content of those blocks instead of the references?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Jos Velasco

    (@josvelasco)

    I see, it doesn’t seem to work for dynamic blocks such as the navigation block.

    Thread Starter Jos Velasco

    (@josvelasco)

    I had to call do_blocks:

    add_filter( 'the_content', 'filter_the_content_in_the_main_loop' );
     
    function filter_the_content_in_the_main_loop( $content ) {
     
        if ( in_the_loop() && is_main_query() ) {
    		
    		$get_block = get_post( 1568 );
       		$menu = $get_block->post_content;	
    		$menu = do_blocks($menu);
    		
    		$get_block = get_post( 1588 );
       		$footer = $get_block->post_content;	
    		$footer = do_blocks($footer);
    		
            return $menu . $content . $footer;
        }
     
        return $content;
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get block content within reusable blocks’ is closed to new replies.