0

I'm getting this warning with development mode:

Warning: join(): Invalid arguments passed in /webDir/project/wp-includes/post-template.php on line 371

In production mode the <article> class attribute becomes blank (class=""). This error corresponds to the next function:

/**
 * Display the classes for the post div.
 *
 * @since 2.7.0
 *
 * @param string|array $class One or more classes to add to the class list.
 * @param int|WP_Post $post_id Optional. Post ID or post object.
 */
function post_class( $class = '', $post_id = null ) {
    // Separates classes with a single space, collates classes for post DIV
    echo 'class="' . join( ' ', get_post_class( $class, $post_id ) ) . '"';
}

After debugging for a while, I've found the issue in the next custom function (functions.php):

/* Remove hentry class from "contact" page */

if(! function_exists( 'remove_hentry' )) {
    function remove_hentry( $classes ) {
        $classes[] = customTheme_layout_class();
        if(is_page('contact')) {            
            $classes = array_diff($classes, array("hentry"));

            return $classes;
        }
    }

    add_filter( 'post_class', 'remove_hentry' );
}

Removing these lines the warning disappears and the <article> classes are shown correctly. customTheme_layout_class() is a theme function with the next code:

/* ------------------------------------------------------------------------- *
 *  Template functions
/* ------------------------------------------------------------------------- */ 

/*  Layout class
/* ------------------------------------ */
if ( ! function_exists( 'customTheme_layout_class' ) ) {

    function customTheme_layout_class() {
        // Default layout
        $layout = 'col-3cm';
        $default = 'col-3cm';

        // Check for page/post specific layout
        if ( is_page() || is_single() ) {
            // Reset post data
            wp_reset_postdata();
            global $post;
            // Get meta
            $meta = get_post_meta($post->ID,'_layout',true);
            // Get if set and not set to inherit
            if ( isset($meta) && !empty($meta) && $meta != 'inherit' ) { $layout = $meta; }
            // Else check for page-global / single-global
            elseif ( is_single() && ( ot_get_option('layout-single') !='inherit' ) ) $layout = ot_get_option('layout-single',''.$default.'');
            elseif ( is_page() && ( ot_get_option('layout-page') !='inherit' ) ) $layout = ot_get_option('layout-page',''.$default.'');
            // Else get global option
            else $layout = ot_get_option('layout-global',''.$default.'');
        }

        // Set layout based on page
        elseif ( is_home() && ( ot_get_option('layout-home') !='inherit' ) ) $layout = ot_get_option('layout-home',''.$default.'');
        elseif ( is_category() && ( ot_get_option('layout-archive-category') !='inherit' ) ) $layout = ot_get_option('layout-archive-category',''.$default.'');
        elseif ( is_archive() && ( ot_get_option('layout-archive') !='inherit' ) ) $layout = ot_get_option('layout-archive',''.$default.'');
        elseif ( is_search() && ( ot_get_option('layout-search') !='inherit' ) ) $layout = ot_get_option('layout-search',''.$default.'');
        elseif ( is_404() && ( ot_get_option('layout-404') !='inherit' ) ) $layout = ot_get_option('layout-404',''.$default.'');

        // Global option
        else $layout = ot_get_option('layout-global',''.$default.'');

        // Return layout class
        return $layout;
    }

}

Any idea of what's the error in my custom function (remove_hentry)?

2

You did not returning the default class if you are not viewing the contact page. Try this code once

if(! function_exists( 'remove_hentry' )) {
    function remove_hentry( $classes ) {
        $classes[] = customTheme_layout_class();
        if( is_page('contact') ) {            
            $classes = array_diff( $classes, array( "hentry" ) );
        }
        return $classes;
    }

    add_filter( 'post_class', 'remove_hentry' );
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.