Home / admin / Display post views within admin post columns
  • How to Display post views within admin post columns


    I posted a cool snippet yesterday to (track post views using post meta) I wanted to add a little to that today. Adding this snippet to the functions.php of your wordpress theme will display the post views next to each post in the wordpress admin.

    ( click code to copy )

    wordpress snippet : PHP

    add_filter('manage_posts_columns', 'posts_column_views');
    add_action('manage_posts_custom_column', 'posts_custom_column_views',5,2);
    function posts_column_views($defaults){
        $defaults['post_views'] = __('Views');
        return $defaults;
    function posts_custom_column_views($column_name, $id){
    	if($column_name === 'post_views'){
            echo getPostViews(get_the_ID());

    ( WordPress codex functions, hooks, in this snippet. )

    manage_posts_columns, get_the_ID, the_ID, add_filter, add_action, __, _n,
  • Tried the snippet on two themes (multisite) – froze the admin pages in both cases and showing only 2 posts for each site. Why would that happen?

    • @facebook-36916051:disqus this should not happen at all I would guess that the snippet may have issues with a pluggin you already have running.  I have never tried this snippet on multi-site version of wordpress so I’m not sure. However it should not be a problem,

      I assume you have this snippet setup

      Then you can use the above to display the post view in a new column but both snippets are required. If you disable all the pluggins you can see if it works then and then enable one by one to see what plugin is a problem.

      •  thank you, Kevin, got it! I did not realize both snippets must be setup for everything to work

  • Xwtiko

    Nice snippet. Is there a way to sort the posts by the number of views? It would be very helpful!

  • Anonymous

    Its working. Thanks
    But sorting the posts based on views would have made it complete. It helps to pull up posts that need more attention to generate traffic.

  • I can’t see view count . In the view count section , I saw this error message

    Fatal error: Call to undefined function echo_views() inE:Softwarexampphtdocswpwp-contentthemesarclitefunctions.php on line 10

  • Nizam Kazi

    I can see Views column at my Dashboard, but view count seems not updating. Do I need different IP? Will it count my IP for at-least once(which it is not doing right now!)

  • Ahmed

    Another option I wish you add
    Sortable Views Column
    It hepls the show the popular posts

  • tonyscialdone

    Interesting. This is a great idea…but it no longer works as intended. When I added it, the Posts list only showed my most recent post. Nothing “broke”, as all posts were live and kept working…it’s just the list that got truncated. I’m loving this site, by the way!


    How to add desc/asc to the column?