Support

Account

Home Forums Gutenberg Sudden prefix: wp-block-acf-

Solved

Sudden prefix: wp-block-acf-

  • After updating ACF the styling of all of our custom blocks broke.

    We have it setup so that we register acf blocks using a function like this:

    function create_acf_block_object($name, $title, $description, $render_template, $dash_icon = 'editor-paste-text', $keywords = array(), $className = false) {
    
    	$acf_block_keywords = array();
    	$acf_object_attributes = array();
    	
    	foreach($keywords as $keyword) {
    		array_push($acf_block_keywords, $keyword);
    	}
    	
    	$acf_object_attributes['name'] 				= $name;
    	$acf_object_attributes['title'] 			= $title;
    	$acf_object_attributes['description'] 		= $description;
    	$acf_object_attributes['render_template'] 	= '/blocks/' . $render_template;
    	$acf_object_attributes['icon'] 				= $dash_icon;
    	$acf_object_attributes['keywords'] 			= $acf_block_keywords;
    	$acf_object_attributes['wpClassName'] 		= $className;
    	$acf_object_attributes['className'] 		= $className;
    	
    	acf_register_block_type($acf_object_attributes);
    	
    }

    In the templates this used to result in $block[‘className’] to contain the $className value provided in the above code.

    Now it appears that the ‘className’ is ignored and instead the $block[‘className’] contains the $name of the block prefixed with “wp-block-acf-”

    This kinda breaks all block styling on saving a post because the classname the style-rules are applied to is now different.

    What would be the easiest way to get rid of this prefix, or add the original classnames?

  • Nvm, I think I got it:

    I had already tried adding the class to the property:
    $acf_object_attributes['wpClassName']

    (as you can see in my original post)

    But I had forgotten to also use output this value in the template: $block[‘wpClassName’], rather than expecting $block[‘className’] to have changed.

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

You must be logged in to reply to this topic.