Archived topic
Default Function No Longer Works
7 replies · Started by Ian on November 7, 2021
So using this to set default GB padding used to work. On a new site, I could not even get functions.php to save. Forced it through using SFTP and now containers still do not contain any padding. Here is what used to work, any ideas?
add_filter( 'generateblocks_defaults', function( $defaults ) {
$defaults['container']['paddingTop'] = '40';
$defaults['container']['paddingRight'] = '25';
$defaults['container']['paddingBottom'] = '40';
$defaults['container']['paddingLeft'] = '25';
return $defaults;
} );
Hi there,
that snippet does still work. For reference i added it back in a code block to maintain formatting:
add_filter( 'generateblocks_defaults', function( $defaults ) {
$defaults['container']['paddingTop'] = '40';
$defaults['container']['paddingRight'] = '25';
$defaults['container']['paddingBottom'] = '40';
$defaults['container']['paddingLeft'] = '25';
return $defaults;
} );
It updates the default values - so it won't affect any Container already added to the site where the default values were updated. Test it by adding a new container block to a page.
That is interesting. On a new site, I tried adding this into functions.php via Wordpress and it would not save. I then forced it in using SFTP and new Containers would not show any numbers inside Spacing. It works well on a previous site but not this one. I wonder if it is a PHP 8 issue. Switched back to PHP 7.4 and added a child theme and the site loads again but just in case this helps, here is the error:
"FastCGI sent in stderr: "PHP message: PHP Warning: Undefined array key "width" in /var/www/domain.com/htdocs/wp-content/themes/generatepress/inc/structure/header.php on line 137PHP message: PHP Warning: Undefined array key "height" in /var/www/domain.com/htdocs/wp-content/themes/generatepress/inc/structure/header.php on line 138" while reading upstream"
Even switching back to PHP 7.4, still cannot save to functions.php with this error popping:
"Unable to communicate back with site to check for fatal errors, so the PHP change was reverted."
Odd?
Can you make sure David's function is added using one of these methods:
Adding PHP: https://docs.generatepress.com/article/adding-php/
It cannot be added to the parent theme's function.php.
Thanks Leo! Using Code Snippets worked. Wonder why adding to functions.php in the child theme no longer works for this latest build. It did last month on a previous site. But thank you!
One more question. Is there a way to use this function and have a default where any new container is automatically tied to a Global Style? I would say 90% of my GB Containers would use this setup.
Can you open a support topic in GB's support forum here?
https://generateblocks.com/support/
Thanks!
After building a bit more, I think I should probably use Global Style instead of the function to do this. Will be easier to update in the future. Thank you!
No problem :)