• Resolved Aaron

    (@jstask)


    When Remove “HTML, JavaScript and CSS comments” is active, it is not possible to use registered block patterns.

    A quick fix would be to not enable this option by default, but maybe this can minify only in the front end?

    • This topic was modified 1 year, 6 months ago by Aaron.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Tim Eckel

    (@teckel)

    Minification must happen on the back-end as it would lose most of its usefulness if done on the front end. Minify HTML provides controls so you can disable certain minifications if it causes a conflict with something specific on your website. I’ve never used a site with block pattern comments, so I’ve never had this situation. But the switch is there in case you have the exact problem you’re experiencing.

    It’s possible that a work-around could be found, but I’d need example HTML output of these block pattern comments as I don’t use that feature to know what they look like.

    But in any case, disabling the comment minification is the solution, and how the plugin was designed to be used.

    Thread Starter Aaron

    (@jstask)

    I prepared a test function for you so you can investigate.

    add_action('init', function () {
    
        register_block_pattern(
            'test',
            [
                'title'       => __('test title', 'text-domain'),
                'description' => __('test description', 'text-domain'),
                'content'     => '<!-- wp:paragraph -->
                <p>Lorem ipsum</p>
                <!-- /wp:paragraph -->',
            ]
        );
    });
    Thread Starter Aaron

    (@jstask)

    Gutenberg blocks can come in various forms, each block is wrapped in comments another example could be

        <!-- wp:arch/text {"size":"sm","customMargin":true,"margin":"lg","content":"Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Praesent commodo cursus magna, vel scelerisque nisl consectetur et."} -->
        <p class="wp-block-arch-text">Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.</p>
        <!-- /wp:arch/text -->

    Unlike my first example, this block is not available in core WordPress.

    However, the comments are only stored in the database as post content. They are only visible inside the Gutenberg editor if you switch to the code editor (shift+cmd+option+m) and are not outputted in the front-end.

    Plugin Author Tim Eckel

    (@teckel)

    It seems block patterns and Minify HTML are using the same hooks, which is why it’s not working. The only solution is to disable comment minification untill a more modern method is used with block patterns, as using HTML comments like they’re doing is really amature hour programming.

    Thread Starter Aaron

    (@jstask)

    Amature or not, this is how it works right now. I suggest disabling this feature then per default, or at least give them a warning in the plugin settings-page, so other users of the plugin don’t run into the same issue.

    Plugin Author Tim Eckel

    (@teckel)

    I’ve never used block patterns, and this is the first time anyone has reported an issue, so leaving it on by default seems okay for now. Maybe someone will change block patterns to use something better than HTML comments as a trigger. And it’s as simple as turning off comment minification until such time, so I see no need to change the default behavior.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Block patterns and comments’ is closed to new replies.