Site logo

Archived topic

Image block defaults

7 replies · Started by Elvis on July 14, 2022

Viewing posts 1–8 of 8

Hello,

there was this discussion https://wordpress.org/support/topic/default-margins-for-containers/#post-13025697 a while ago.

I would like to have defaults in posts and pages for the image block to be:

centered
large size
padding 48px

Following the logic from the discussion I listed above and some more searching i have tried this.

function apuri_generateblocks_spacing( $defaults ) {
	$defaults['image']['alignment']      = 'center';
	$defaults['image']['sizeSlug']       = 'large';
	$defaults['image']['paddingTop']     = '48px';
	$defaults['image']['paddingRight']   = '48px';
	$defaults['image']['paddingBottom']  = '48px';
	$defaults['image']['paddingLeft']    = '48px';
	return $defaults;
}
add_filter( 'generateblocks_defaults', 'apuri_generateblocks_spacing' );

I have also tried setting the global styles like this.

add_filter( 'generateblocks_default_block_styles', function( $styles ) {
    $styles['image']['alignment']      = 'center';
		$styles['image']['sizeSlug']       = 'large';
		$styles['image']['paddingTop']     = '48px';
		$styles['image']['paddingRight']   = '48px';
		$styles['image']['paddingBottom']  = '48px';
		$styles['image']['paddingLeft']    = '48px';
    return $styles;
} );

No luck. What am I doing wrong?
Best,
Elvis

Hi Elvis,

try this:

add_filter( 'generateblocks_defaults', function( $defaults ) {
    $defaults['image']['alignment'] = 'center';
    $defaults['image']['sizeSlug'] = 'large';
    $defaults['image']['paddingTop'] = '20';
    $defaults['image']['paddingRight'] = '20';
    $defaults['image']['paddingBottom'] = '20';
    $defaults['image']['paddingLeft'] = '20';

    return $defaults;
} );

Thanks Ying, thanks David.
Ying you are right.
SizeSlug unfortunately does not work. :(

Will use local patterns here.
lp
Elvis

Damn, SizeSlug does not work as local pattern either.
The size is written in the sidebar but not applied unless I set to another, and then go back to that size ... like it has to relaod it.

Its a JS Variable and currently those don't reflect the defaults.
Its on the 1.5.5 milestone so should be fixed on the next update.

Thanks

You're welcome

This archived topic is closed to new replies.