0

Hey all i have this code here:

if ( !function_exists('AddThumbColumn') && function_exists('add_theme_support') ) {
    // for post and page
    add_theme_support('post-thumbnails', array( 'post', 'page' ) );

    function AddThumbColumn($cols) {
        $cols['thumbnail'] = __('Header Images');
        return $cols;
    }

    function AddThumbValue($column_name, $post_id) {
        echo 'Header Image data here';
    }

    add_filter( 'manage_pages_columns', 'AddThumbColumn' );
    add_action( 'manage_pages_custom_column', 'AddThumbValue', 10, 2 );

    function AddThumbColumn2($cols) {
        $cols['cssColor'] = __('CSS Color');
        return $cols;
    }

    function AddThumbValue2($column_name, $post_id) {
        //code goes here for second column      
    }

    add_filter( 'manage_pages_columns', 'AddThumbColumn2' );
    add_action( 'manage_pages_custom_column', 'AddThumbValue2', 10, 2 );
}

And that works with creating 2 separate columns (Header Images, CSS Color) but it seems to duplicate the data in Header Images in the CSS color..?

What am i missing in order to have each column separate with data for its own?

1 Answer 1

1

functions attached to manage_pages_custom_column get fired for every custom column, you have to check the name of the column within the function to only output data for that specific column:

add_action( 'manage_pages_custom_column', 'AddColumnValue', 10, 2 );

function AddColumnValue( $column_name, $post_id ) {
    if( 'thumbnail' == $column_name ):
        echo 'Header Image data here';
    elseif( 'cssColor' == $column_name ):
        //code goes here for second column
    endif;
}
0

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