0

I need to display a little description of the posts on the post lists page, i.e inside Post page of admin dashboard. It is already displaying title, author, categories, tags, comment, date, and so on. but how can i fetch post excerpt to be displayed here beside title.

1 Answer 1

0

Please add follwing line of code in your theme's function.php to display a new column which will display excerpt in your posts.

function pkb_get_excerpt($post_ID) {
    $content_post = get_post($post_ID);
$content = $content_post->post_content;
    if ($content) {
      return $content;
    }
}

// ADD NEW COLUMN
function pkb_columns_head($defaults) {
    $defaults['excerpt'] = 'excerpt';
    return $defaults;
}

// SHOW THE EXCERPT
function pkb_columns_content($column_name, $post_ID) {
    if ($column_name == 'excerpt') {
        $post_content = pkb_get_excerpt($post_ID);
        echo $str1= substr ($post_content,0,50);

    }
}

add_filter('manage_posts_columns', 'pkb_columns_head');
add_action('manage_posts_custom_column', 'pkb_columns_content', 10, 2);

Please feel free to ask if you have any queries.

3
  • Thank you! Its working. Do you know How can I print specific columns? Or get them on a separate page. I want to print post title, excerpt and Post id.
    – Maryam
    Jul 20, 2017 at 9:01
  • Do you mean you need to display it in frontend? I did not understand your query Jul 26, 2017 at 6:47
  • Yes i need to print it on the front end.
    – Maryam
    Jul 31, 2017 at 11:19

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.