Blocks enable us to use WordPress as a page builder tool. We can use the core WordPress blocks or create our own blocks and combine them in a certain way to create a page. Right now the template files of our excellence-block theme have hardcoded static code. In the classic Excellence theme, we used PHP to dynamically get much of the information on a page dynamically, like the title, content, banner area etc. In this lesson, we will see how to achieve the same in a block theme.

Navigate to the block editor from the admin dashboard by clicking on "Appearance" and then "Editor." Open the Single Post template that we created in the last lesson. Right now, the template has a paragraph with a test message.

Post title and content blocks

Let’s say we want to display the title of the blog post dynamically. WordPress has a block named "Post Title." We can use it to dynamically fetch the title of a post or page.

To add a new block in the template file, type a forward slash. It displays a list of all the available blocks. Type /post title and select the post title block.

Get hands-on with 1200+ tech skills courses.