Support

Account

Home Forums Gutenberg Gutenberg Block not showing in frontend

Solving

Gutenberg Block not showing in frontend

  • I created a new block and added fields to it using ACF Pro.

    acf_register_block([
      'name' => 'incontent',
      'title' => __('In-Content Teaser'),
      'description' => __('Teaser Element mit Bild, volle Breite.'),
      'render_template' => get_theme_file_path()."/resources/blocks/incontent.php",
      'category' => 'layout',
      'icon' => 'align-center',
      'keywords' => ['teaser'],
    ]);

    The block shows fine in the backend editor, I can change the content and everything. But it just doesn’t show up on the actual page. The data is there, but the output file doesn’t seem to be used.

    Here is the output from the inspector:

     wp:acf/incontent {
        "id": "block_5d81fa6dbbf5a",
        "name": "acf\/incontent",
        "data": {
            "bild": 303,
            "_bild": "field_5d81fa0de504f",
            "text": "Some text.]",
            "_text": "field_5d81fa20e5050",
            "link": {
                "title": "Page",
                "url": "https:\/\/dev.url.de\/page\/",
                "target": ""
            },
            "_link": "field_5d81fa38e5051"
        },
        "align": "",
        "mode": "preview"
    } /

    This is my render file:

    <?php
    /**
     * Block Name: In-Content Teaser
     */
    
    print('die');
    
    die();
    
    $bild = wp_get_attachment_image(get_field('bild'), 'large', '', ["alt" => ""]);
    $text = get_field('text');
    $link = get_field('link');
    ?>
    
    <div class="gutenberg-incontent">
      <?php echo $bild; ?>
      <a href="<?php echo $link['url']; ?>">
        <?php echo $text; ?>
      </a>
    </div>

    Note that the print and die are for my debbugging right now. Those statements do get executed when editing the page in the backend, but not when looking at the page in the frontend. However, checking with file_exists shows that the code can find my render file in both cases.

    Any idea why it’s not being executed?

  • I’m suddenly having the same issue after it working fine before. Do you know what was causing this for you?

  • Did you find a fix for this? There’s literally no answers anywhere on why it is happening 🙁

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.