[Resolved] Default Function No Longer Works

Home Forums Support [Resolved] Default Function No Longer Works

Home Forums Support Default Function No Longer Works

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1994548
    Ian

    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;
    } );

    #1994955
    David
    Staff
    Customer Support

    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.

    #1995052
    Ian

    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?

    #1995096
    Leo
    Staff
    Customer Support

    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.

    #1995155
    Ian

    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.

    #1995174
    Leo
    Staff
    Customer Support

    Can you open a support topic in GB’s support forum here?
    https://generateblocks.com/support/

    Thanks!

    #1995176
    Ian

    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!

    #1995185
    Leo
    Staff
    Customer Support

    No problem 🙂

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.