0

I'm trying to understand how themes are constructed. One of the themes I've read has this in its templates/index.html:

<!-- wp:template-part {"slug":"header","theme":"themename","area":"header"} /-->

<!-- wp:group {"tagName":"main","style":{"spacing":{"padding":
{"top":"40px","bottom":"40px","left":"var:preset|spacing|40","right":"var:preset|
spacing|40"}}},"layout":{"type":"constrained","contentSize":"100%"}} -->
<main
  class="wp-block-group"
  style="
    padding-top: 40px;
    padding-right: var(--wp--preset--spacing--40);
    padding-bottom: 40px;
    padding-left: var(--wp--preset--spacing--40);
  ">

  <!-- wp:group {"style":{"spacing":{"padding":{"left":"0","right":"0"}}},"layout":
{"type":"constrained","contentSize":"1240px"}} -->
  <div class="wp-block-group" style="padding-right: 0; padding-left: 0">
    <!-- wp:columns -->
    <div class="wp-block-columns">
    (…)

So, this is somehow the same, but … twice? What is the point of doing this?

1 Answer 1

3

The <!-- wp: tags are how the WordPress editor internal api control what has been generated on the page and it contains the data that is generated or controlled by the settings panel of the editor. In general, those settings are directly converted to some html / style that you see on the page but not always. That's why it seems duplicated. One is for the editor internal control and the other is for the browser to display. For more info about it, take a look at the Markup representation of a block of the Block Editor Handbook.

If you really want to understand it, I advise you to take a look at the technical overview introduction and the Key concepts from the Block Editor Handbook. The Handbook has a lot more of information and you should read it if you want a more in deep understanding of full site editing, blocks and block themes.

5
  • So instead of using data-*-atttributes on the block (that already is the html-tag from opening to close), they came up with… this!?
    – rhavin
    Commented Aug 3 at 17:10
  • @rhavin data-* and <!-- wp: serves a really different purpose. You can have <!-- wp: that does not directly translate do html/styles and you also have the problem of the diference between dynamic and static rendering. You should probably take some time to read all the shared docs and also make some tests with the editor to get a better grasp of it.
    – Iogui
    Commented Aug 3 at 17:16
  • @logui I did and opted for ClassicPress. Abusing HTML-comments for something that should be inside css, data-attributes or custom tags is not a thing I want coming from my servers. On top of that, the same output from the old wordpress-site and the new classic-press-site is about 70% less styling- and scripting-scrap.
    – rhavin
    Commented Aug 8 at 10:12
  • That's up to you, @rhavin. If you are willing to give up the added benefits of the blocks and if working the classic way cover all your needs, then I see no problem. I prefer to be able to use the FSE features.
    – Iogui
    Commented Aug 9 at 17:38
  • @rhavin As a side note, if you are going to discard all the benefits of the new architecture of the WordPress then why to use it at all? That are other CMS you can use. Have you tried Joomla or Drupal?
    – Iogui
    Commented Aug 9 at 18:11

Your Answer

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

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