Toolbox for Beaver Builder

toolbox/helpers/set_acfimage_classes

Sets the default classes for the ACF image field when adding it with an img- tag.

The classes can be added using the filter, or by adding a filter that enables an attribute to pass in the classes.

Parameters

  • $classes (array)
  • $attr (string)

Usage

If the classes defining the image aren't enough for you you can always add more. This example adds a  new attribute and function so that you can add classes using the [toolbox] shortcode.

<?php

add_filter( 'toolbox/helpers/sc_attr/type=image' , 'add_image_class_attr' , 10 ,1 );

// add a custom attribute named 'myclass'
function add_image_class_attr( $attr ) {
	$attr['myclass'] = '';
	return $attr;
}

add_filter( 'toolbox/helpers/set_acfimage_classes' , 'enable_custom_image_classes', 10, 2 );

// add the custom atrtibute 'myclass' to the $classes array
function enable_custom_image_classes( $classes , $attr ) {

	if (isset($attr['myclass']) && $attr['myclass'] !='' ) {
		array_push( $classes , $attr['myclass'] );
	}

	return $classes;
	
}

You can now add classes with extra classes using the shortcode:

[toolbox field='imagefield' tag='true' size='thumbnail' myclass='mycustomclass']

 

Last modified: October 30th, 2018