Site logo

Archived topic

Hero block using the new block element

3 replies · Started by Lox on October 18, 2020

Viewing posts 1–4 of 4

Hello,

I am trying to build a hero block for every page but home page. I need it to use the current post feature image as background (with a fallback to a default image) and the post title. {{post_title}} isn't working in a block element.

Did I miss something ?

Regards.

Hi,

To clarify: Are you trying to use the Block Element as a page-hero section alternative to Header Element?

If yes, {{post_title}} is not the way to go as it will only work on Header Element.

To work on Block Elements (Gutenberg Editor), you'll have to find a way to make a block display the post title.

One way to do that is through making your own shortcode.

Here's an example of a PHP snippet displaying post title w/ [post_title] shortcode.

add_shortcode( 'post_title', function() {
    ob_start();
    // Start your PHP below
  	echo get_the_title(get_the_id());
    // End your PHP above
    return ob_get_clean();
} );

Other alternatives may require installing additional plugins that add dynamic text blocks to Gutenberg Editor.

Ok thanks.

What about using the feature image of the current post as background for the container block ?

Something like this would be awesome and easy to implement:

Hi there,

featured images are planned for a future update where the Block Element will support dynamic content.

This archived topic is closed to new replies.