Support

Account

Home Forums Gutenberg No rendering in front end

Solved

No rendering in front end

  • Hi !

    I tried to register a block with acf as followed:

    add_action('acf/init', 'bwb_content_gallery');
    function bwb_content_gallery() {
    
       // Check function exists.
    	if( function_exists('acf_register_block_type') ) {
    
    		// register a testimonial block.
    		acf_register_block_type(array(
    			'name'              => 'bwb_gallery',
    			'title'             => __('Galerie Lexuberance'),
    			'description'       => __(''),
    			'render_callback'   => 'acf_render_callback',
    			'category'          => 'formating',
    			'icon'              => 'schedule',
    			'keywords'          => array( 'gallery', 'lexuberance' ),
    			'mode'				  => 'edit'
    		));
    	}
    }

    To have a rendering I used ‘render_template’ as first but nothing appears in front-end.
    To avoid any path issues with my template I decided to use ‘render_callback’ then.

    function acf_render_callback( $block, $content = "", $is_preview = false, $post_id = 0 ) {
    	?>
    	<p>RENDERING</p>
    	<?php
    }
    

    “RENDERING” is showing in the editor but nothing in front-end.

    Am I missing something ? How to render my block in front-end ?

  • Hello,

    Were you able to resolve this? I have the same issue and I have searched everywhere for a solution but so far no luck.

    Thanks

  • Why are there no answers to this question!?!??! It’s been asked quite a bit across various sites.

    My issue is essentially the same apart from the JSON for the ACF block is being loaded in the DOM but the block isn’t being rendered. Surely someone has an answer since it’s not a one-off issue that people are experiencing??

  • Alright, I completely forgot about that.
    I hope it’ll help you but to resolve my problem it looks like I just changed the way to call my template.

    add_action('acf/init', 'bwb_content_gallery');
    function bwb_content_gallery() {
    
       // Check function exists.
    	if( function_exists('acf_register_block_type') ) {
    
    		// register a testimonial block.
    		acf_register_block_type(array(
    			'name'              => 'bwb_gallery',
    			'title'             => __('Galerie Lexuberance'),
    			'description'       => __(''),
    			'render_template'   => './templates/blocks/gallery.php',
    			'category'          => 'formating',
    			'icon'              => 'schedule',
    			'keywords'          => array( 'gallery', 'lexuberance' ),
    			'mode'				  => 'edit',
    			'enqueue_style'     => get_template_directory_uri() . '/dist/css/blocks.css',
    		));
    	}
    }

    As you can see in “render_template” I directly put the path to the template I want to see and it does work.

  • Thanks for the response, and for finding your code from 1 year and a half ago – much appreciated! Unfortunately I’ve not had any luck with render_template option either. All renders fine within the editor, but nothing on the front end. I’ll keep digging though. Thanks! 🙂

  • Mine was resolved just like @paulg stated. But perhaps you can try this plugin https://hookturn.io/downloads/acf-theme-code-pro/ if you’re not already aware. It automatically generates a php code immediately after you create AFC fields. The tutorial has very clear instructions

  • Same issue on our end, anyone got extra info on this?

  • In our case we we’re missing the do_blocks call when echoing the post_content.

  • @perrelet can you take a look at the new documentation here at https://www.advancedcustomfields.com/resources/whats-new-with-acf-blocks-in-acf-6/ to see if it helps.

    There’s a quote that may or may not be applicable to your question:

    WordPress 5.9 users who use Block Styles may have noticed that the ACF registration of styles was not applied to those previews, which is why all ACF Block users should migrate their blocks to use those WordPress provided methods of asset loading.

  • @dareadel We experienced the same issue using the native block.json format. For us we just needed to call do_blocks in order to get either method working.

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

You must be logged in to reply to this topic.