Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

When you click on "Posts" or "Pages", you get a paged listing of your posts or pages with the following columns:

Title | Author | Categories | Tags | Date

I have a plugin which gives an SEO score for each post and page. I would like to add two columns to the list view when viewing posts or pages, one for the post's "seo score" and one for the posts "seo keyword" so that the column listing becomes:

Title | Author | Categories | Tags | Date | SEO Score | SEO Keywords

share|improve this question
add comment

1 Answer

up vote 11 down vote accepted

You add the column using the manage_posts_column filter, where you add two new array elements with a custom key name and the header name as the value.

add_filter('manage_posts_columns', 'add_seo_columns', 10, 2);
function add_dummy_column($posts_columns, $post_type)
{
    $posts_columns['seo_score'] = 'SEO score';
    $posts_columns['seo_keyword'] = 'SEO keyword';
    return $posts_columns;
}

The function that displays each row, _post_row(), then fires the manage_posts_custom_column action for each column that it does not know. You hook into this function to display your own data.

add_action('manage_posts_custom_column', 'display_seo_columns', 10, 2);
function display_seo_columns($column_name, $post_id)
{
    if ('seo_score' == $column_name) {
        echo 'SEO score for post with ID ' . $post_id;
    }
    if ('seo_keyword' == $column_name) {
        echo 'SEO keyword for post with ID ' . $post_id;
    }
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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