Tet banner

Custom Fields
Support MB Blocks Block doesn't render on frontend

  • Creator
  • #17762
    Resolved Jackky

    Hi! I'm trying to male my first block and it's working perfect on backend, but on frontend appers nothing. I can't find out why.

    Block template:

    echo 'test output';
    if ( empty( $attributes['data'] ) ) return;
    $data = to_object($attributes['data']);
    <?php if ($data->triggers) { ?>
    <div class="text-trigger">
        <?php foreach ($data->triggers as $trigger) { ?>
        <div class="text-trigger__item">
            <div class="text-trigger__item-inner">
                <div class="text-trigger__item-icon" style="background-image: url(<?= wp_get_attachment_image_url($trigger->icon, 'icon-0x100'); ?>);"></div>
                <div class="text-trigger__item-text">
                    <?= $trigger->text; ?>
        <?php } ?>
    <?php } ?>


    $meta_boxes[] = [
        'title'           => 'Текстовые триггеры',
        'id'              => 'text-trigger',
        //'description'     => 'A custom hero content block',
        'type'            => 'block',
        'icon'            => 'awards',
        'category'        => 'layout',
        'context'         => 'side',
        'render_template' => get_template_directory() . '/gutenberg/text-trigger.php',
        'supports' => [
            'align' => ['wide', 'full'],
        'fields'          => [
                'id'                => 'triggers',
                'type'              => 'group',
                'name'              => 'Контент',
                'clone'             => true,
                'sort_clone'        => true,
                'add_button'        => '+',
                'fields'            => [
                        'id'            => 'icon',
                        'type'          => 'single_image',
                        'name'          => 'Иконка',
                        'id'            => 'text',
                        'type'          => 'text',
                        'name'          => 'Текст',
Viewing 4 replies - 1 through 4 (of 4 total)
  • Author
  • #17763

    I have find out the issue. It's because I'm wrapping init of mb in is_admin condition like this:

    if (is_admin()) {
        add_filter( 'rwmb_meta_boxes', 'register_meta_boxes' );
        add_filter( 'mb_settings_pages', 'settings_pages' );

    How can I load render template on frontend with saving this condition?

    Anh Tran

    Hi Jackky,

    The condition is_admin() should never be used. It prevents the fields/settings available for retrieving the data on the front end.


    Yeah, I know, but it's likely for me to disable every functions that I'm not using in frontend for security purposes. So I wanna make a suggestion to make some filters for MB, that allows to load only that functions I need, like rendering block template, not all helpers.

    Anh Tran

    I'm afraid it's not possible. All meta boxes and fields when registered will be added to a registry. That makes the helper functions to be able to find them to get the field settings and get field value. It's an integral part of the plugin and can't be disabled.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.