I get an error in WordPress function when I filter the page's alias
P粉946336138
2023-08-17 17:30:15
<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>
This function only returns the
$classes
variable ifis_shop()
is true, when in fact it should always return the$classes
variable:Filters must always return a value; if they do not return a value, an error will almost always be raised.