0

I'm using this code to add a block before the entry title on the front page but its not working:

$e      = get_block( '552' ); 
$eblock = apply_filters( 'the_content', $e->post_content );

echo $eblock;

Note : The code works fine within the content area but not outside the loop.

I also tried do_blocks() but it prints multiple instances of the output which is form HTML.

$get_block = get_post( '552' );
$footer = $get_block->post_content; 
$out = do_blocks($footer);

return $title .  $out;

Here's where i got the reusable block ID http://example.com/wp-admin/post.php?post=552&action=edit

It must have something to do with add_filter('the_title', i'm using because it works fine when i echo it without a hook.

4
  • 1
    There's no function called get_block(). What is '552'? What is this code supposed to do? Apr 22 at 8:14
  • 552 is the ID for the reusable block which i want to output using PHP. See update
    – Michelle
    Apr 22 at 9:15
  • There's a get_block() on WP_REST_Block_Types_Controller but you can't mean that. Where does that function come from?
    – Rup
    Apr 22 at 9:22
  • From a discussion on the WordPress forums
    – Michelle
    Apr 22 at 9:27

1 Answer 1

0

I worked this out. The code for the_title filter was causing the problem so i added the code to the entry header template part and it works fine.

echo apply_filters( 'the_content', get_post_field('post_content', '552' ) );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.