I get an error in WordPress function when I filter the page's alias
P粉946336138
P粉946336138 2023-08-17 17:30:15
0
1
500
<p>This works fine on the store page but throws an error on other pages. </p> <p>This has to do with if(is_page('shop')). </p> <p><br /></p> <pre class="brush:html;toolbar:false;">function divi_engine_body_class( $classes ) { if(is_page('shop')) { $classes[] = 'woocommerce-page-SGARAGLINO'; return $classes; } } add_filter('body_class','divi_engine_body_class',99999);</pre> <p><br /></p> <p>Error message: PHP Fatal Error: Uncaught TypeError: array_unique(): Parameter #1 ($array) must be of type array, in /wordpress/core/6.2.2/wp-includes/post-template.php: Null is given at 861. </p>
P粉946336138
P粉946336138

reply all(1)
P粉269530053

This function only returns the $classes variable if is_shop() is true, when in fact it should always return the $classes variable:

function divi_engine_body_class( $classes ) {
   if ( is_page( 'shop' ) ) {
        $classes[] = 'woocommerce-page-SGARAGLINO';
    }

    return $classes;
}

Filters must always return a value; if they do not return a value, an error will almost always be raised.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template