1

Lots of plugins provide both shortcodes and PHP for adding elements... either directly in a page or post, or programmatically in a theme template. Is there a process for adding a Block, like Latest Posts, directly to a theme using PHP? I imagine it might be like this:

<?php add_block('latest_posts'); ?>

I'm running 5.9.3. Thanks!

3
  • As I understand, how this is done depends on the context: Is this for a custom post type that you made or for all new posts (of post type posts) or for a specific kind of page template (that is of the post type 'page')?
    – Will
    Commented Apr 24, 2022 at 17:41
  • 1
    Thanks! It's not for any post type... more for being able to put block content into templates. You know, like building a footer with existing blocks. If we can put "latest posts" (for example) in the template, it will show up on every page. I'm just not sure if it's possible, or how to do it. I've seen no documentation on it, so I thought I'd reach out.
    – GodWords
    Commented Apr 25, 2022 at 18:52
  • 1
    If I understand you correctly that you're using a php (defined as a classic theme at developer.wordpress.org/block-editor/how-to-guides/themes) theme. As I understand this might be possible; but developer.wordpress.org/themes/block-themes/… might steer toward the right direction where you have some HTML templates and then some templates in php.
    – Will
    Commented Apr 28, 2022 at 17:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.