• Resolved Imagedemonboy

    (@demonboy)


    Please excuse my ignorance as I’m new to HTML block themes (I’m used to PHP). I want to use them as I see all the advantages, but I seem to be constantly hitting brick walls with pulling dynamic content.

    For example, I have an icon, which sits in an HTML block, to link to the post within a query loop. Normally, I’d do something like this:

    <div data-post-id="{post_id}">

    I am trying to avoid using plugins and custom javascript but I’m finding HTML blocks restrictive outside of the usual WP blocks. I’m using twentytwentyfour as my parent theme.

    Is there a standard practice to handle this kind of thing? Should I be building my own custom block?

Viewing 4 replies - 1 through 4 (of 4 total)
  • ImageAvinash Zala

    (@avinashzala01)

    You can check the query loop here in this case I think that will help you to solve issue. I came to this conclusion based on your question that you want to pass the post_id in some HTML structure and I think that can be done. Still if you need more help feel free to elaborate your exact requirements so we can help you out.

    Moderator Imagethreadi

    (@threadi)

    As far as I know, there are no placeholders in the HTML block. In this case, you would have to use classic shortcodes, which you can write in PHP (which you should already be familiar with) – but you would encounter a nasty bug that has unfortunately been around in Gutenberg for quite some time: https://github.com/WordPress/gutenberg/issues/43053 – possible solutions are described in this issue.

    Thread Starter Imagedemonboy

    (@demonboy)

    Hi @threadi Thanks for getting back to me. I had come across this issue already and was trying to avoid shortcodes, but it seems the only solution. How this is still a bug since 2022 is pretty bad. I will endevour to find a solution in the comments. Cheers.

    Thread Starter Imagedemonboy

    (@demonboy)

    Further to this and the useful thread @threadi provided, I ended up using a plugin to solve this issue. I didn’t want to go down the plugin route, but the few hard-coded solutions I tried continued to cause headaches. However, it seems the 5* Meta Field Block plugin is well-coded and light, written by an active developer who offers great support. If you are hitting the shortcode in a query loop issue (by default, shortcodes run after the loop has run and therefore miss things like post ID), then this plugin is essential.

Viewing 4 replies - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.