Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor Mike Jolley

    (@mikejolley)

    What error and what code?

    Thread Starter Bryan Cady

    (@bobcatou)

    Here is the code snippet.

    //* Add custom body class to the head
    add_filter( 'body_class', 'bg_shop_add_body_class' );
    function bg_shop_add_body_class( $classes ) {
      if (is_shop()) {
        $classes[] = 'bg-shop';
        return $classes;
      }
    }

    Here is the error I got. It looks like it is a conflict with Genesis..

    [10-Jun-2016 14:04:59 UTC] PHP Catchable fatal error:  Argument 1 passed to genesis_custom_body_class() must be of the type array, null given in /Applications/MAMP/htdocs/bahnsengallery-v1/wp-content/themes/genesis/lib/structure/layout.php on line 61

    The code the error is referring to is

    /**
     * Add custom field body class(es) to the body classes.
     *
     * It accepts values from a per-post or per-page custom field, and only outputs when viewing a singular page.
     *
     * @since 1.4.0
     *
     * @uses genesis_get_custom_field() Get custom field value.
     *
     * @param array $classes Existing classes.
     *
     * @return array Amended classes.
     */
    function genesis_custom_body_class( array $classes ) {
    
    	$new_class = is_singular() ? genesis_get_custom_field( '_genesis_custom_body_class' ) : null;
    
    	if ( $new_class )
    		$classes[] = $new_class;
    
    	return $classes;
    
    }

    I think this might be conflicting with the way Genesis allows you to create a custom class on the admin edit page. There is a field to do that. When I add a class there, it doesn’t take so I figured there must be something special with the Shop page.

    That was why I was wondering if there was a special way to create a class on that page?

    Bryan

    Move your return $classes outside the is_shop conditional because you want to return the classes regardless of whether the condition is met or not.

    eg

    //* Add custom body class to the head
    add_filter( 'body_class', 'bg_shop_add_body_class' );
    function bg_shop_add_body_class( $classes ) {
      if (is_shop()) {
        $classes[] = 'bg-shop';
      }
      return $classes;
    }
    Thread Starter Bryan Cady

    (@bobcatou)

    Deleted this…Jo beat me to it. Thanks Jo

    Plugin Contributor Mike Jolley

    (@mikejolley)

    if (is_shop()) {
        $classes[] = 'bg-shop';
        return $classes;
      }

    should be:

    if (is_shop()) {
        $classes[] = 'bg-shop';
      }
     return $classes;
    Thread Starter Bryan Cady

    (@bobcatou)

    This is solved. Thanks Mike

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How do you assign a class to the "Shop" page’ is closed to new replies.