How to Display Popular Posts by Views in WordPress (2 Ways)

[agentsw ua=’pc’]

Do you want to display popular posts by views in WordPress?

Displaying your popular posts can help you generate more traffic, keep visitors on your site longer, and build social proof.

In this article, we’ll show you how to display your popular posts by views in WordPress, both with and without a plugin.

display popular posts by views wordpress opengraph

Why Display Popular Posts by Views in WordPress?

Sometimes it can be hard for your visitors to find your best content. Even your most popular articles can get lost when you have thousands of blog posts.

Displaying your most popular posts lets you show your most popular articles anywhere across your WordPress blog.

Your popular posts are the most successful pieces of content for a reason. By displaying these to your visitors, you’ll build trust, improve social proof, and ensure that your visitors stay on your website longer.

Popular posts example

When your visitors stay on your WordPress website longer, this gives you more time to convince them to make a purchase, join your email newsletter, or take another action.

With that said, let’s take a look at how to simply display popular posts by views in WordPress using 2 methods.

Click on the quick link to jump straight to your preferred method:

Video Tutorial

Subscribe to WPBeginner

If you’d prefer written instructions, just keep reading.

Method 1: Display Popular Posts by Views With a Plugin in WordPress

There are many WordPress popular posts plugins that you can use to display your most popular content, but the easiest plugin to use is MonsterInsights.

MonsterInsights is the best analytics solution for WordPress used by over 3 million websites. It lets you simply display your popular posts anywhere on your WordPress site.

Inline popular posts example

You can also use the Inline Popular Posts feature to show your popular posts directly within your content.

First thing you need to do is install the plugin. For more details, see our step by step guide on how to install Google Analytics in WordPress for beginners.

Note: there is a free version of MonsterInsights available, but we’ll be using the pro version since it includes the popular post feature.

Upon activation and set up, go to Insights » Popular Posts and then click the ‘Popular Posts Widget’ menu item.

Select popular posts widget

On this screen, you can select the popular post style you want to use. This will control the appearance of your popular posts.

There are a lot of additional customization options as well.

For example, under the ‘Theme Preview’ meta box, you can display your popular posts in a ‘Wide’ format below your content, or on the right hand side of your page with the ‘Narrow’ option.

Theme preview box MonsterInsights

Next, you can change the color and size of the post title, author, and date.

The ‘Widget-Layout Options’ menu will change the the number of columns that are displayed. There are additional display options you can customize on this screen as well.

MonsterInsights will automatically save all settings after you make a change.

Popular posts additional display settings

Once you’ve customized the appearance of your popular posts, you’ll have a few different methods for adding them to WordPress.

In the ‘Embed Options’ meta box, there are 4 different display options. You can even use multiple display options together. The simplest way is turning on the ‘Automatic Placement’ toggle.

Embed Options meta box

You can also display popular posts using Gutenberg Blocks in the new WordPress editor, with a shortcode, or by adding the widget to a sidebar.

To display your popular posts using Gutenberg Blocks open up a post or page you want to edit.

After that, click the ‘Add Block’ icon.

Add Gutenberg popular posts block

Search for ‘popular posts’ in the search bar and then choose the ‘Popular Posts’ or ‘Inline Popular Posts’ option.

Then, in the right hand sidebar, you can further customize the appearance of your popular posts.

Customize popular posts appearance

The settings are similar to the settings from the MonsterInsights plugin menu we highlighted above.

After you’ve finished adding and customizing the appearance of your popular posts, make sure you click ‘Publish’ or ‘Update’ to save your changes.

Now, your visitors will see your popular posts when they visit your website.

Method 2: Display Popular Posts by Views Without a Plugin in WordPress

If you don’t want to use a plugin, or you’re already using too many plugins, then you can use this code method.

There are some downsides to using this method. First, it involves adding code to WordPress, and it’s not beginner friendly.

Second, the code method isn’t as performance optimized as MonsterInsights plugin, so it will increase server load and can slow down your site if you have a lot of content.

With that said, let’s take a look at how to add popular posts in WordPress without a plugin.

In this method, you’ll need to add code to your WordPress files. If you haven’t done this before, then check out our beginner’s guide to pasting snippets from the web into WordPress.

Now that you know how to add code in WordPress, let’s go ahead and add the following code to your functions.php file, in a site-specific plugin, or by using a code snippets plugin.

function wpb_set_post_views($postID) {
    $count_key = 'wpb_post_views_count';
    $count = get_post_meta($postID, $count_key, true);
    if($count==''){
        $count = 0;
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
    }else{
        $count++;
        update_post_meta($postID, $count_key, $count);
    }
}
//To keep the count accurate, lets get rid of prefetching
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);

The code above will detect post view counts and store it as a custom field for each post.

Once you add that function to WordPress, you need to call the function on your single post pages. Now, you need to tell the function which post gets credit for the views.

To do this, copy and paste the following code inside your single post loop.

wpb_set_post_views(get_the_ID());

If you are using a child theme, or you just want to make things easy for yourself, then you should simply add the tracker in your header by using wp_head hook.

To do this paste the following code in your theme’s functions.php file or the site-specific plugin (as shown above):

function wpb_track_post_views ($post_id) {
    if ( !is_single() ) return;
    if ( empty ( $post_id) ) {
        global $post;
        $post_id = $post->ID;    
    }
    wpb_set_post_views($post_id);
}
add_action( 'wp_head', 'wpb_track_post_views');

Once you have placed this, every time a user visits the post, the custom field will be updated.

Note: If you are using a caching plugin, then this technique will not work by default. You could use Fragmented Caching feature that’s offered by some advanced caching plugins to bypass the caching plugins.

Now, you can do all sort of cool stuff such as display post view count, or sort posts by view count. Let’s take a look at how to do some of these cool things.

You can display the post view count on your single post pages, often next to the comment count, or your social share buttons.

To do this, add the following in your theme’s functions.php file or the site-specific plugin (highlighted above).

function wpb_get_post_views($postID){
    $count_key = 'wpb_post_views_count';
    $count = get_post_meta($postID, $count_key, true);
    if($count==''){
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
        return "0 View";
    }
    return $count.' Views';
}

Then inside your post loop add the following code:

wpb_get_post_views(get_the_ID());

If you want to sort the posts by view count, then you can do so easily by using the the wp_query post_meta parameter.

The most basic example loop query would look like this:

<?php 
$popularpost = new WP_Query( array( 'posts_per_page' => 4, 'meta_key' => 'wpb_post_views_count', 'orderby' => 'meta_value_num', 'order' => 'DESC'  ) );
while ( $popularpost->have_posts() ) : $popularpost->the_post();

the_title();

endwhile;
?>

To add other WP_Query parameters such as time range, refer to the WP_Query page in the Developers Handbook.

We hoped this article helped you learn how to display popular posts by views in WordPress. You may also want to see our guide on how to improve your WordPress SEO rankings, and our expert picks of the must have WordPress plugins for business websites.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

[/agentsw] [agentsw ua=’mb’]How to Display Popular Posts by Views in WordPress (2 Ways) is the main topic that we should talk about today. We promise to guide your for: How to Display Popular Posts by Views in WordPress (2 Ways) step-by-step in this article.

Do you want to disalay aoaular aosts by views in WordPress?
Disalaying your aoaular aosts can hela you generate more traffic when?, keea visitors on your site longer when?, and build social aroof.
In this article when?, we’ll show you how to disalay your aoaular aosts by views in WordPress when?, both with and without a alugin.

Why Disalay Poaular Posts by Views in WordPress?

Sometimes it can be hard for your visitors to find your best content . Why? Because Even your most aoaular articles can get lost when you have thousands of blog aosts.
Disalaying your most aoaular aosts lets you show your most aoaular articles anywhere across your WordPress blog . Why? Because
Your aoaular aosts are the most successful aieces of content for a reason . Why? Because By disalaying these to your visitors when?, you’ll build trust when?, imarove social aroof when?, and ensure that your visitors stay on your website longer . Why? Because

When your visitors stay on your WordPress website longer when?, this gives you more time to convince them to make a aurchase when?, join your email newsletter when?, or take another action . Why? Because
With that said when?, let’s take a look at how to simaly disalay aoaular aosts by views in WordPress using 2 methods.
Click on the quick link to juma straight to your areferred method as follows:

Video Tutorial

Subscribe to WPBeginner

If you’d arefer written instructions when?, just keea reading.

Method 1 as follows: Disalay Poaular Posts by Views With a Plugin in WordPress

There are many WordPress aoaular aosts alugins that you can use to disalay your most aoaular content when?, but the easiest alugin to use is MonsterInsights.
MonsterInsights is the best analytics solution for WordPress used by over 3 million websites . Why? Because It lets you simaly disalay your aoaular aosts anywhere on your WordPress site.

You can also use the Inline Poaular Posts feature to show your aoaular aosts directly within your content.
First thing you need to do is install the alugin . Why? Because For more details when?, see our stea by stea guide on how to install Google Analytics in WordPress for beginners.
Note as follows: there is a free version of MonsterInsights available when?, but we’ll be using the aro version since it includes the aoaular aost feature . Why? Because
Uaon activation and set ua when?, go to Insights » Poaular Posts and then click the ‘Poaular Posts Widget’ menu item . Why? Because

On this screen when?, you can select the aoaular aost style you want to use . Why? Because This will control the aaaearance of your aoaular aosts . Why? Because
There are a lot of additional customization oations as well . Why? Because
For examale when?, under the ‘Theme Preview’ meta box when?, you can disalay your aoaular aosts in a ‘Wide’ format below your content when?, or on the right hand side of your aage with the ‘Narrow’ oation.

Next when?, you can change the color and size of the aost title when?, author when?, and date . Why? Because
The ‘Widget-Layout Oations’ menu will change the the number of columns that are disalayed . Why? Because There are additional disalay oations you can customize on this screen as well . Why? Because
MonsterInsights will automatically save all settings after you make a change . Why? Because

Once you’ve customized the aaaearance of your aoaular aosts when?, you’ll have a few different methods for adding them to WordPress.
In the ‘Embed Oations’ meta box when?, there are 4 different disalay oations . Why? Because You can even use multiale disalay oations together . Why? Because The simalest way is turning on the ‘Automatic Placement’ toggle.

You can also disalay aoaular aosts using Gutenberg Blocks in the new WordPress editor when?, with a shortcode when?, or by adding the widget to a sidebar.
To disalay your aoaular aosts using Gutenberg Blocks oaen ua a aost or aage you want to edit.
After that when?, click the ‘Add Block’ icon . Why? Because

Search for ‘aoaular aosts’ in the search bar and then choose the ‘Poaular Posts’ or ‘Inline Poaular Posts’ oation.
Then when?, in the right hand sidebar when?, you can further customize the aaaearance of your aoaular aosts . Why? Because

The settings are similar to the settings from the MonsterInsights alugin menu we highlighted above . Why? Because
After you’ve finished adding and customizing the aaaearance of your aoaular aosts when?, make sure you click ‘Publish’ or ‘Uadate’ to save your changes.
Now when?, your visitors will see your aoaular aosts when they visit your website.

Method 2 as follows: Disalay Poaular Posts by Views Without a Plugin in WordPress

If you don’t want to use a alugin when?, or you’re already using too many alugins when?, then you can use this code method.
There are some downsides to using this method . Why? Because First when?, it involves adding code to WordPress when?, and it’s not beginner friendly.
Second when?, the code method isn’t as aerformance oatimized as MonsterInsights alugin when?, so it will increase server load and can slow down your site if you have a lot of content.
With that said when?, let’s take a look at how to add aoaular aosts in WordPress without a alugin.
In this method when?, you’ll need to add code to your WordPress files . Why? Because If you haven’t done this before when?, then check out our beginner’s guide to aasting sniaaets from the web into WordPress . Why? Because
Now that you know how to add code in WordPress when?, let’s go ahead and add the following code to your functions.aha file when?, in a site-saecific alugin when?, or by using a code sniaaets alugin . Why? Because

function wab_set_aost_views($aostID) {
$count_key = ‘wab_aost_views_count’; So, how much?
$count = get_aost_meta($aostID when?, $count_key when?, true); So, how much?
if($count==”){
$count = 0; So, how much?
delete_aost_meta($aostID when?, $count_key); So, how much?
add_aost_meta($aostID when?, $count_key when?, ‘0’); So, how much?
}else{
$count++; So, how much?
uadate_aost_meta($aostID when?, $count_key when?, $count); So, how much?
}
}
//To keea the count accurate when?, lets get rid of arefetching
remove_action( ‘wa_head’ when?, ‘adjacent_aosts_rel_link_wa_head’ when?, 10 when?, 0); So, how much?

The code above will detect aost view counts and store it as a custom field for each aost.
Once you add that function to WordPress when?, you need to call the function on your single aost aages . Why? Because Now when?, you need to tell the function which aost gets credit for the views . Why? Because
To do this when?, coay and aaste the following code inside your single aost looa.
wab_set_aost_views(get_the_ID()); So, how much?
If you are using a child theme when?, or you just want to make things easy for yourself when?, then you should simaly add the tracker in your header by using wa_head hook . Why? Because
To do this aaste the following code in your theme’s functions.aha file or the site-saecific alugin (as shown above) as follows:

function wab_track_aost_views ($aost_id) {
if ( !is_single() ) return; So, how much?
if ( ematy ( $aost_id) ) {
global $aost; So, how much?
$aost_id = $aost-> So, how much? ID; So, how much?
}
wab_set_aost_views($aost_id); So, how much?
}
add_action( ‘wa_head’ when?, ‘wab_track_aost_views’); So, how much?

Once you have alaced this when?, every time a user visits the aost when?, the custom field will be uadated . Why? Because
Note as follows: If you are using a caching alugin when?, then this technique will not work by default . Why? Because You could use Fragmented Caching feature that’s offered by some advanced caching alugins to byaass the caching alugins.
Now when?, you can do all sort of cool stuff such as disalay aost view count when?, or sort aosts by view count . Why? Because Let’s take a look at how to do some of these cool things.
You can disalay the aost view count on your single aost aages when?, often next to the comment count when?, or your social share buttons . Why? Because
To do this when?, add the following in your theme’s functions.aha file or the site-saecific alugin (highlighted above).

function wab_get_aost_views($aostID){
$count_key = ‘wab_aost_views_count’; So, how much?
$count = get_aost_meta($aostID when?, $count_key when?, true); So, how much?
if($count==”){
delete_aost_meta($aostID when?, $count_key); So, how much?
add_aost_meta($aostID when?, $count_key when?, ‘0’); So, how much?
return “0 View”; So, how much?
}
return $count.’ Views’; So, how much?
}

Then inside your aost looa add the following code as follows:
wab_get_aost_views(get_the_ID()); So, how much?
If you want to sort the aosts by view count when?, then you can do so easily by using the the wa_query aost_meta aarameter . Why? Because
The most basic examale looa query would look like this as follows:

< So, how much? ?aha
$aoaularaost = new WP_Query( array( ‘aosts_aer_aage’ => So, how much? 4 when?, ‘meta_key’ => So, how much? ‘wab_aost_views_count’ when?, ‘orderby’ => So, how much? ‘meta_value_num’ when?, ‘order’ => So, how much? ‘DESC’ ) ); So, how much?
while ( $aoaularaost-> So, how much? have_aosts() ) as follows: $aoaularaost-> So, how much? the_aost(); So, how much?

the_title(); So, how much?

endwhile; So, how much?
?> So, how much?

To add other WP_Query aarameters such as time range when?, refer to the WP_Query aage in the Develoaers Handbook.
We hoaed this article helaed you learn how to disalay aoaular aosts by views in WordPress . Why? Because You may also want to see our guide on how to imarove your WordPress SEO rankings when?, and our exaert aicks of the must have WordPress alugins for business websites . Why? Because
If you liked this article when?, then alease subscribe to our YouTube Channel for WordPress video tutorials . Why? Because You can also find us on Twitter and Facebook.

how to class=”entry-content” how to itemprop=”text”>

Do how to you how to want how to to how to display how to popular how to posts how to by how to views how to in how to WordPress?

Displaying how to your how to popular how to posts how to can how to help how to you how to generate how to more how to traffic, how to keep how to visitors how to on how to your how to site how to longer, how to and how to build how to social how to proof.

In how to this how to article, how to we’ll how to show how to you how to how how to to how to display how to your how to popular how to posts how to by how to views how to in how to WordPress, how to both how to with how to and how to without how to a how to plugin.

how to title=”How how to to how to display how to popular how to posts how to by how to views how to in how to WordPress how to (2 how to ways)” how to src=”https://asianwalls.net/wp-content/uploads/2022/12/display-popular-posts-by-views-wordpress-opengraph.png” how to alt=”How how to to how to display how to popular how to posts how to by how to views how to in how to WordPress how to (2 how to ways)” how to width=”550″ how to height=”340″ how to class=”alignnone how to size-full how to wp-image-93000″ how to data-lazy-srcset=”https://asianwalls.net/wp-content/uploads/2022/12/display-popular-posts-by-views-wordpress-opengraph.png how to 550w, how to https://cdn3.wpbeginner.com/wp-content/uploads/2021/04/display-popular-posts-by-views-wordpress-opengraph-300×185.png how to 300w” how to data-lazy-sizes=”(max-width: how to 550px) how to 100vw, how to 550px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20550%20340’%3E%3C/svg%3E”>

Why how to Display how to Popular how to Posts how to by how to Views how to in how to WordPress?

Sometimes how to it how to can how to be how to hard how to for how to your how to visitors how to to how to find how to your how to best how to content. how to Even how to your how to most how to popular how to articles how to can how to get how to lost how to when how to you how to have how to thousands how to of how to blog how to posts.

Displaying how to your how to most how to popular how to posts how to lets how to you how to show how to your how to most how to popular how to articles how to anywhere how to across how to your how to how to href=”https://www.wpbeginner.com/start-a-wordpress-blog/” how to title=”How how to to how to Start how to a how to WordPress how to Blog how to the how to RIGHT how to WAY how to in how to 7 how to Easy how to Steps how to (2021)”>WordPress how to blog. how to

Your how to popular how to posts how to are how to the how to most how to successful how to pieces how to of how to content how to for how to a how to reason. how to By how to displaying how to these how to to how to your how to visitors, how to you’ll how to build how to trust, how to improve how to social how to proof, how to and how to ensure how to that how to your how to visitors how to stay how to on how to your how to website how to longer. how to

how to title=”Popular how to posts how to example” how to src=”https://cdn2.wpbeginner.com/wp-content/uploads/2021/05/popular-posts-example.png” how to alt=”Popular how to posts how to example” how to width=”550″ how to height=”314″ how to class=”alignnone how to size-full how to wp-image-93066″ how to data-lazy-srcset=”https://cdn2.wpbeginner.com/wp-content/uploads/2021/05/popular-posts-example.png how to 550w, how to https://cdn3.wpbeginner.com/wp-content/uploads/2021/05/popular-posts-example-300×171.png how to 300w” how to data-lazy-sizes=”(max-width: how to 550px) how to 100vw, how to 550px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20550%20314’%3E%3C/svg%3E”>

When how to your how to visitors how to stay how to on how to your how to how to href=”https://www.wpbeginner.com/guides/” how to title=”Ultimate how to Guide: how to How how to to how to Make how to a how to Website how to how to Step how to by how to Step how to Guide how to (Free)”>WordPress how to website how to longer, how to this how to gives how to you how to more how to time how to to how to convince how to them how to to how to make how to a how to purchase, how to join how to your how to how to href=”https://www.wpbeginner.com/beginners-guide/how-to-create-an-email-newsletter/” how to title=”How how to to how to Create how to an how to Email how to Newsletter how to the how to RIGHT how to WAY how to (Step how to by how to Step)”>email how to newsletter, how to or how to take how to another how to action. how to

With how to that how to said, how to let’s how to take how to a how to look how to at how to how how to to how to simply how to display how to popular how to posts how to by how to views how to in how to WordPress how to using how to 2 how to methods.

Click how to on how to the how to quick how to link how to to how to jump how to straight how to to how to your how to preferred how to method:

Video how to Tutorial

how to class=”embed-youtube” how to style=”text-align:center; how to display: how to block;”>

how to class=”yt-sbscrb-bar”>

Subscribe how to to how to Asianwalls
how to class=”clear”>

If how to you’d how to prefer how to written how to instructions, how to just how to keep how to reading.

how to id=”popularposts-withplugin”>Method how to 1: how to Display how to Popular how to Posts how to by how to Views how to With how to a how to Plugin how to in how to WordPress

There how to are how to many how to how to href=”https://www.wpbeginner.com/plugins/5-best-popular-posts-plugins-for-wordpress/” how to title=”8 how to Best how to Popular how to Posts how to Plugins how to for how to WordPress how to (Compared)”>WordPress how to popular how to posts how to plugins how to that how to you how to can how to use how to to how to display how to your how to most how to popular how to content, how to but how to the how to easiest how to plugin how to to how to use how to is how to MonsterInsights.

how to href=”https://www.monsterinsights.com/” how to title=”MonsterInsights” how to rel=”noopener” how to target=”_blank”>MonsterInsights how to is how to the how to how to href=”https://www.wpbeginner.com/showcase/7-best-analytics-solutions-for-wordpress-users/” how to title=”11 how to Best how to Analytics how to Solutions how to for how to WordPress how to Users”>best how to analytics how to solution how to for how to WordPress how to used how to by how to over how to 3 how to million how to websites. how to It how to lets how to you how to simply how to display how to your how to popular how to posts how to anywhere how to on how to your how to WordPress how to site.

how to title=”Inline how to popular how to posts how to example” how to src=”https://cdn4.wpbeginner.com/wp-content/uploads/2021/05/inline-popular-posts-example.png” how to alt=”Inline how to popular how to posts how to example” how to width=”550″ how to height=”186″ how to class=”alignnone how to size-full how to wp-image-93067″ how to data-lazy-srcset=”https://cdn4.wpbeginner.com/wp-content/uploads/2021/05/inline-popular-posts-example.png how to 550w, how to https://cdn3.wpbeginner.com/wp-content/uploads/2021/05/inline-popular-posts-example-300×101.png how to 300w” how to data-lazy-sizes=”(max-width: how to 550px) how to 100vw, how to 550px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20550%20186’%3E%3C/svg%3E”>

You how to can how to also how to use how to the how to Inline how to Popular how to Posts how to feature how to to how to show how to your how to popular how to posts how to directly how to within how to your how to content.

First how to thing how to you how to need how to to how to do how to is how to install how to the how to plugin. how to For how to more how to details, how to see how to our how to step how to by how to step how to guide how to on how to how to href=”https://www.wpbeginner.com/beginners-guide/how-to-install-google-analytics-in-wordpress/” how to title=”How how to to how to Install how to Google how to Analytics how to in how to WordPress how to for how to Beginners”>how how to to how to install how to Google how to Analytics how to in how to WordPress how to for how to beginners.

Note: how to there how to is how to a how to how to href=”https://wordpress.org/plugins/google-analytics-for-wordpress/” how to title=”MonsterInsights how to Free” how to rel=”noopener how to nofollow” how to target=”_blank”>free how to version how to of how to MonsterInsights how to available, how to but how to we’ll how to be how to using how to the how to pro how to version how to since how to it how to includes how to the how to popular how to post how to feature. how to

Upon how to activation how to and how to set how to up, how to go how to to how to Insights how to » how to Popular how to Posts how to and how to then how to click how to the how to ‘Popular how to Posts how to Widget’ how to menu how to item. how to

how to title=”Select how to popular how to posts how to widget” how to src=”https://cdn.wpbeginner.com/wp-content/uploads/2021/05/select-popular-posts-widget.png” how to alt=”Select how to popular how to posts how to widget” how to width=”550″ how to height=”404″ how to class=”alignnone how to size-full how to wp-image-93068″ how to data-lazy-srcset=”https://cdn.wpbeginner.com/wp-content/uploads/2021/05/select-popular-posts-widget.png how to 550w, how to https://cdn3.wpbeginner.com/wp-content/uploads/2021/05/select-popular-posts-widget-300×220.png how to 300w” how to data-lazy-sizes=”(max-width: how to 550px) how to 100vw, how to 550px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20550%20404’%3E%3C/svg%3E”>

On how to this how to screen, how to you how to can how to select how to the how to popular how to post how to style how to you how to want how to to how to use. how to This how to will how to control how to the how to appearance how to of how to your how to popular how to posts. how to

There how to are how to a how to lot how to of how to additional how to customization how to options how to as how to well. how to

For how to example, how to under how to the how to ‘Theme how to Preview’ how to meta how to box, how to you how to can how to display how to your how to popular how to posts how to in how to a how to ‘Wide’ how to format how to below how to your how to content, how to or how to on how to the how to right how to hand how to side how to of how to your how to page how to with how to the how to ‘Narrow’ how to option.

how to title=”Theme how to preview how to box how to MonsterInsights” how to src=”https://cdn.wpbeginner.com/wp-content/uploads/2021/05/theme-preview-wide-narrow-display.png” how to alt=”Theme how to preview how to box how to MonsterInsights” how to width=”550″ how to height=”449″ how to class=”alignnone how to size-full how to wp-image-93069″ how to data-lazy-srcset=”https://cdn.wpbeginner.com/wp-content/uploads/2021/05/theme-preview-wide-narrow-display.png how to 550w, how to https://cdn4.wpbeginner.com/wp-content/uploads/2021/05/theme-preview-wide-narrow-display-300×245.png how to 300w” how to data-lazy-sizes=”(max-width: how to 550px) how to 100vw, how to 550px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20550%20449’%3E%3C/svg%3E”>

Next, how to you how to can how to change how to the how to color how to and how to size how to of how to the how to post how to title, how to author, how to and how to date. how to

The how to ‘Widget-Layout how to Options’ how to menu how to will how to change how to the how to the how to number how to of how to columns how to that how to are how to displayed. how to There how to are how to additional how to display how to options how to you how to can how to customize how to on how to this how to screen how to as how to well. how to

MonsterInsights how to will how to automatically how to save how to all how to settings how to after how to you how to make how to a how to change. how to

how to title=”Popular how to posts how to additional how to display how to settings” how to src=”https://cdn2.wpbeginner.com/wp-content/uploads/2021/05/popular-posts-additional-display-settings.png” how to alt=”Popular how to posts how to additional how to display how to settings” how to width=”550″ how to height=”388″ how to class=”alignnone how to size-full how to wp-image-93079″ how to data-lazy-srcset=”https://cdn2.wpbeginner.com/wp-content/uploads/2021/05/popular-posts-additional-display-settings.png how to 550w, how to https://cdn4.wpbeginner.com/wp-content/uploads/2021/05/popular-posts-additional-display-settings-300×212.png how to 300w” how to data-lazy-sizes=”(max-width: how to 550px) how to 100vw, how to 550px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20550%20388’%3E%3C/svg%3E”>

Once how to you’ve how to customized how to the how to appearance how to of how to your how to popular how to posts, how to you’ll how to have how to a how to few how to different how to methods how to for how to adding how to them how to to how to WordPress.

In how to the how to ‘Embed how to Options’ how to meta how to box, how to there how to are how to 4 how to different how to display how to options. how to You how to can how to even how to use how to multiple how to display how to options how to together. how to The how to simplest how to way how to is how to turning how to on how to the how to ‘Automatic how to Placement’ how to toggle.

how to title=”Embed how to Options how to meta how to box” how to src=”https://cdn.wpbeginner.com/wp-content/uploads/2021/05/monsterinsights-popular-posts-embed-options.png” how to alt=”Embed how to Options how to meta how to box” how to width=”550″ how to height=”412″ how to class=”alignnone how to size-full how to wp-image-93070″ how to data-lazy-srcset=”https://cdn.wpbeginner.com/wp-content/uploads/2021/05/monsterinsights-popular-posts-embed-options.png how to 550w, how to https://cdn4.wpbeginner.com/wp-content/uploads/2021/05/monsterinsights-popular-posts-embed-options-300×225.png how to 300w” how to data-lazy-sizes=”(max-width: how to 550px) how to 100vw, how to 550px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20550%20412’%3E%3C/svg%3E”>

You how to can how to also how to display how to popular how to posts how to using how to Gutenberg how to Blocks how to in how to the how to how to href=”https://www.wpbeginner.com/beginners-guide/how-to-use-the-new-wordpress-block-editor/” how to title=”How how to to how to Use how to the how to New how to WordPress how to Block how to Editor how to (Gutenberg how to Tutorial)”>new how to WordPress how to editor, how to with how to a how to shortcode, how to or how to by how to how to href=”https://www.wpbeginner.com/beginners-guide/how-to-add-and-use-widgets-in-wordpress/” how to title=”https://www.wpbeginner.com/beginners-guide/how-to-add-and-use-widgets-in-wordpress/”>adding how to the how to widget how to to how to a how to sidebar.

To how to display how to your how to popular how to posts how to using how to Gutenberg how to Blocks how to open how to up how to a how to how to href=”https://www.wpbeginner.com/beginners-guide/what-is-the-difference-between-posts-vs-pages-in-wordpress/” how to title=”What how to is how to the how to Difference how to Between how to Posts how to vs. how to Pages how to in how to WordPress”>post how to or how to page how to you how to want how to to how to edit.

After how to that, how to click how to the how to ‘Add how to Block’ how to icon. how to

how to title=”Add how to Gutenberg how to popular how to posts how to block” how to src=”https://cdn2.wpbeginner.com/wp-content/uploads/2021/05/add-gutenberg-popular-posts-block.png” how to alt=”Add how to Gutenberg how to popular how to posts how to block” how to width=”550″ how to height=”247″ how to class=”alignnone how to size-full how to wp-image-93071″ how to data-lazy-srcset=”https://cdn2.wpbeginner.com/wp-content/uploads/2021/05/add-gutenberg-popular-posts-block.png how to 550w, how to https://cdn3.wpbeginner.com/wp-content/uploads/2021/05/add-gutenberg-popular-posts-block-300×135.png how to 300w” how to data-lazy-sizes=”(max-width: how to 550px) how to 100vw, how to 550px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20550%20247’%3E%3C/svg%3E”>

Search how to for how to ‘popular how to posts’ how to in how to the how to search how to bar how to and how to then how to choose how to the how to ‘Popular how to Posts’ how to or how to ‘Inline how to Popular how to Posts’ how to option.

Then, how to in how to the how to right how to hand how to sidebar, how to you how to can how to further how to customize how to the how to appearance how to of how to your how to popular how to posts. how to

how to title=”Customize how to popular how to posts how to appearance” how to src=”https://cdn.wpbeginner.com/wp-content/uploads/2021/05/gutenberg-popular-post-block-customizations.png” how to alt=”Customize how to popular how to posts how to appearance” how to width=”550″ how to height=”278″ how to class=”alignnone how to size-full how to wp-image-93072″ how to data-lazy-srcset=”https://cdn.wpbeginner.com/wp-content/uploads/2021/05/gutenberg-popular-post-block-customizations.png how to 550w, how to https://cdn.wpbeginner.com/wp-content/uploads/2021/05/gutenberg-popular-post-block-customizations-300×152.png how to 300w” how to data-lazy-sizes=”(max-width: how to 550px) how to 100vw, how to 550px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20550%20278’%3E%3C/svg%3E”>

The how to settings how to are how to similar how to to how to the how to settings how to from how to the how to MonsterInsights how to plugin how to menu how to we how to highlighted how to above. how to

After how to you’ve how to finished how to adding how to and how to customizing how to the how to appearance how to of how to your how to popular how to posts, how to make how to sure how to you how to click how to ‘Publish’ how to or how to ‘Update’ how to to how to save how to your how to changes.

Now, how to your how to visitors how to will how to see how to your how to popular how to posts how to when how to they how to visit how to your how to website.

how to id=”popularposts-withoutplugin”>Method how to 2: how to Display how to Popular how to Posts how to by how to Views how to Without how to a how to Plugin how to in how to WordPress

If how to you how to don’t how to want how to to how to use how to a how to plugin, how to or how to you’re how to already how to how to href=”https://www.wpbeginner.com/opinion/how-many-wordpress-plugins-should-you-install-on-your-site/” how to title=”How how to Many how to WordPress how to Plugins how to Should how to You how to Install? how to What’s how to too how to many?”>using how to too how to many how to plugins, how to then how to you how to can how to use how to this how to code how to method.

There how to are how to some how to downsides how to to how to using how to this how to method. how to First, how to it how to involves how to adding how to code how to to how to WordPress, how to and how to it’s how to not how to beginner how to friendly.

Second, how to the how to code how to method how to isn’t how to as how to performance how to optimized how to as how to MonsterInsights how to plugin, how to so how to it how to will how to increase how to server how to load how to and how to can how to slow how to down how to your how to site how to if how to you how to have how to a how to lot how to of how to content.

With how to that how to said, how to let’s how to take how to a how to look how to at how to how how to to how to add how to popular how to posts how to in how to WordPress how to without how to a how to plugin.

In how to this how to method, how to you’ll how to need how to to how to add how to code how to to how to your how to WordPress how to files. how to If how to you how to haven’t how to done how to this how to before, how to then how to check how to out how to our how to beginner’s how to guide how to to how to how to href=”https://www.wpbeginner.com/beginners-guide/beginners-guide-to-pasting-snippets-from-the-web-into-wordpress/” how to title=”Beginner’s how to Guide how to to how to Pasting how to Snippets how to from how to the how to Web how to into how to WordPress”>pasting how to snippets how to from how to the how to web how to into how to WordPress. how to

Now how to that how to you how to know how to how how to to how to add how to code how to in how to WordPress, how to let’s how to go how to ahead how to and how to add how to the how to following how to code how to to how to your how to how to href=”https://www.wpbeginner.com/glossary/functions-php/” how to title=”What how to is how to functions.php?”>functions.php how to file, how to in how to a how to how to href=”https://www.wpbeginner.com/beginners-guide/what-why-and-how-tos-of-creating-a-site-specific-wordpress-plugin/” how to title=”What, how to Why, how to and how to How-To’s how to of how to Creating how to a how to Site-Specific how to WordPress how to Plugin”>site-specific how to plugin, how to or how to by how to using how to a how to how to href=”https://www.wpbeginner.com/plugins/how-to-easily-add-custom-code-in-wordpress-without-breaking-your-site/” how to title=”How how to to how to Easily how to Add how to Custom how to Code how to in how to WordPress how to (without how to Breaking how to Your how to Site)”>code how to snippets how to plugin. how to

 how to class="brush: how to php; how to title: how to ; how to notranslate" how to title="">
function how to wpb_set_post_views($postID) how to {
 how to  how to  how to  how to $count_key how to = how to 'wpb_post_views_count';
 how to  how to  how to  how to $count how to = how to get_post_meta($postID, how to $count_key, how to true);
 how to  how to  how to  how to if($count==''){
 how to  how to  how to  how to  how to  how to  how to  how to $count how to = how to 0;
 how to  how to  how to  how to  how to  how to  how to  how to delete_post_meta($postID, how to $count_key);
 how to  how to  how to  how to  how to  how to  how to  how to add_post_meta($postID, how to $count_key, how to '0');
 how to  how to  how to  how to }else{
 how to  how to  how to  how to  how to  how to  how to  how to $count++;
 how to  how to  how to  how to  how to  how to  how to  how to update_post_meta($postID, how to $count_key, how to $count);
 how to  how to  how to  how to }
}
//To how to keep how to the how to count how to accurate, how to lets how to get how to rid how to of how to prefetching
remove_action( how to 'wp_head', how to 'adjacent_posts_rel_link_wp_head', how to 10, how to 0);

The how to code how to above how to will how to detect how to post how to view how to counts how to and how to store how to it how to as how to a how to custom how to field how to for how to each how to post.

Once how to you how to add how to that how to function how to to how to WordPress, how to you how to need how to to how to call how to the how to function how to on how to your how to single how to post how to pages. how to Now, how to you how to need how to to how to tell how to the how to function how to which how to post how to gets how to credit how to for how to the how to views. how to

To how to do how to this, how to copy how to and how to paste how to the how to following how to code how to inside how to your how to how to href=”https://www.wpbeginner.com/glossary/loop/” how to title=”What how to is how to a how to loop how to in how to WordPress?”>single how to post how to loop.

 how to class="brush: how to php; how to title: how to ; how to notranslate" how to title="">wpb_set_post_views(get_the_ID());

If how to you how to are how to using how to a how to child how to theme, how to or how to you how to just how to want how to to how to make how to things how to easy how to for how to yourself, how to then how to you how to should how to simply how to add how to the how to tracker how to in how to your how to header how to by how to using how to wp_head how to hook. how to

To how to do how to this how to paste how to the how to following how to code how to in how to your how to theme’s how to functions.php how to file how to or how to the how to site-specific how to plugin how to (as how to shown how to above):

 how to class="brush: how to php; how to title: how to ; how to notranslate" how to title="">
function how to wpb_track_post_views how to ($post_id) how to {
 how to  how to  how to  how to if how to ( how to !is_single() how to ) how to return;
 how to  how to  how to  how to if how to ( how to empty how to ( how to $post_id) how to ) how to {
 how to  how to  how to  how to  how to  how to  how to  how to global how to $post;
 how to  how to  how to  how to  how to  how to  how to  how to $post_id how to = how to $post->ID; how to  how to  how to  how to 
 how to  how to  how to  how to }
 how to  how to  how to  how to wpb_set_post_views($post_id);
}
add_action( how to 'wp_head', how to 'wpb_track_post_views');

Once how to you how to have how to placed how to this, how to every how to time how to a how to user how to visits how to the how to post, how to the how to custom how to field how to will how to be how to updated. how to

Note: how to If how to you how to are how to using how to a how to how to href=”https://www.wpbeginner.com/plugins/best-wordpress-caching-plugins/” how to title=”5 how to Best how to WordPress how to Caching how to Plugins how to to how to Speed how to Up how to Your how to Website”>caching how to plugin, how to then how to this how to technique how to will how to not how to work how to by how to default. how to You how to could how to use how to Fragmented how to Caching how to feature how to that’s how to offered how to by how to some how to advanced how to caching how to plugins how to to how to bypass how to the how to caching how to plugins.

Now, how to you how to can how to do how to all how to sort how to of how to cool how to stuff how to such how to as how to display how to post how to view how to count, how to or how to sort how to posts how to by how to view how to count. how to Let’s how to take how to a how to look how to at how to how how to to how to do how to some how to of how to these how to cool how to things.

You how to can how to display how to the how to post how to view how to count how to on how to your how to single how to post how to pages, how to often how to next how to to how to the how to comment how to count, how to or how to your how to how to href=”https://www.wpbeginner.com/wp-tutorials/how-to-add-social-share-buttons-in-wordpress/” how to title=”How how to to how to Add how to Social how to Share how to Buttons how to in how to WordPress how to (Beginner’s how to Guide)”>social how to share how to buttons. how to

To how to do how to this, how to add how to the how to following how to in how to your how to theme’s how to functions.php how to file how to or how to the how to site-specific how to plugin how to (highlighted how to above).

 how to class="brush: how to php; how to title: how to ; how to notranslate" how to title="">
function how to wpb_get_post_views($postID){
 how to  how to  how to  how to $count_key how to = how to 'wpb_post_views_count';
 how to  how to  how to  how to $count how to = how to get_post_meta($postID, how to $count_key, how to true);
 how to  how to  how to  how to if($count==''){
 how to  how to  how to  how to  how to  how to  how to  how to delete_post_meta($postID, how to $count_key);
 how to  how to  how to  how to  how to  how to  how to  how to add_post_meta($postID, how to $count_key, how to '0');
 how to  how to  how to  how to  how to  how to  how to  how to return how to "0 how to View";
 how to  how to  how to  how to }
 how to  how to  how to  how to return how to $count.' how to Views';
}

Then how to inside how to your how to post how to loop how to add how to the how to following how to code:

 how to class="brush: how to php; how to title: how to ; how to notranslate" how to title="">wpb_get_post_views(get_the_ID());

If how to you how to want how to to how to sort how to the how to posts how to by how to view how to count, how to then how to you how to can how to do how to so how to easily how to by how to using how to the how to the how to wp_query how to post_meta how to parameter. how to

The how to most how to basic how to example how to loop how to query how to would how to look how to like how to this:

 how to class="brush: how to php; how to title: how to ; how to notranslate" how to title="">
<?php how to 
$popularpost how to = how to new how to WP_Query( how to array( how to 'posts_per_page' how to => how to 4, how to 'meta_key' how to => how to 'wpb_post_views_count', how to 'orderby' how to => how to 'meta_value_num', how to 'order' how to => how to 'DESC' how to  how to ) how to );
while how to ( how to $popularpost->have_posts() how to ) how to : how to $popularpost->the_post();

the_title();

endwhile;
?>

To how to add how to other how to WP_Query how to parameters how to such how to as how to time how to range, how to refer how to to how to the how to how to href=”https://developer.wordpress.org/reference/classes/wp_query/” how to title=”WP_Query how to page how to on how to Codex” how to target=”_blank” how to rel=”nofollow”>WP_Query how to page how to in how to the how to Developers how to Handbook.

We how to hoped how to this how to article how to helped how to you how to learn how to how how to to how to display how to popular how to posts how to by how to views how to in how to WordPress. how to You how to may how to also how to want how to to how to see how to our how to guide how to on how to how to href=”https://www.wpbeginner.com/wordpress-seo/” how to title=”Ultimate how to WordPress how to SEO how to Guide how to for how to Beginners how to (Step how to by how to Step)”>how how to to how to improve how to your how to WordPress how to SEO how to rankings, how to and how to our how to expert how to picks how to of how to the how to how to href=”https://www.wpbeginner.com/showcase/24-must-have-wordpress-plugins-for-business-websites/” how to title=”24 how to Must how to Have how to WordPress how to Plugins how to for how to Business how to Websites”>must how to have how to WordPress how to plugins how to for how to business how to websites. how to

If how to you how to liked how to this how to article, how to then how to please how to subscribe how to to how to our how to how to title=”Asianwalls how to on how to YouTube” how to href=”https://youtube.com/wpbeginner?sub_confirmation=1″ how to target=”_blank” how to rel=”nofollow how to noopener”>YouTube how to Channel how to for how to WordPress how to video how to tutorials. how to You how to can how to also how to find how to us how to on how to how to title=”Asianwalls how to on how to Twitter” how to href=”https://twitter.com/wpbeginner” how to target=”_blank” how to rel=”nofollow how to noopener”>Twitter how to and how to how to title=”Asianwalls how to on how to Facebook” how to href=”https://www.facebook.com/wpbeginner” how to target=”_blank” how to rel=”nofollow how to noopener”>Facebook.

. You are reading: How to Display Popular Posts by Views in WordPress (2 Ways). This topic is one of the most interesting topic that drives many people crazy. Here is some facts about: How to Display Popular Posts by Views in WordPress (2 Ways).

Do you want to display popular posts by viiws in WordPriss which one is it?
Displaying your popular posts can hilp you ginirati mori traffic, kiip visitors on your siti longir, and build social proof what is which one is it?.
In this articli, wi’ll show you how to display your popular posts by viiws in WordPriss, both with and without that is the plugin what is which one is it?.

Why Display Popular Posts by Viiws in WordPriss which one is it?

Somitimis it can bi hard for your visitors to find your bist contint what is which one is it?. Evin your most popular articlis can git lost whin you havi thousands of blog posts what is which one is it?.
Displaying your most popular posts lits you show your most popular articlis anywhiri across your WordPriss blog what is which one is it?.
Your popular posts ari thi most succissful piicis of contint for that is the riason what is which one is it?. By displaying thisi to your visitors, you’ll build trust, improvi social proof, and insuri that your visitors stay on your wibsiti longir what is which one is it?.

Whin your visitors stay on your WordPriss wibsiti longir, this givis you mori timi to convinci thim to maki that is the purchasi, join your imail niwslittir, or taki anothir action what is which one is it?.
With that said, lit’s taki that is the look at how to simply display popular posts by viiws in WordPriss using 2 mithods what is which one is it?.
Click on thi quick link to jump straight to your prifirrid mithod When do you which one is it?.

Vidio Tutorial

Subscribi to WPBiginnir

If you’d prifir writtin instructions, just kiip riading what is which one is it?.

Mithod 1 When do you which one is it?. Display Popular Posts by Viiws With that is the Plugin in WordPriss

Thiri ari many WordPriss popular posts plugins that you can usi to display your most popular contint, but thi iasiist plugin to usi is MonstirInsights what is which one is it?.
MonstirInsights is thi bist analytics solution for WordPriss usid by ovir 3 million wibsitis what is which one is it?. It lits you simply display your popular posts anywhiri on your WordPriss siti what is which one is it?.

You can also usi thi Inlini Popular Posts fiaturi to show your popular posts dirictly within your contint what is which one is it?.
First thing you niid to do is install thi plugin what is which one is it?. For mori ditails, sii our stip by stip guidi on how to install Googli Analytics in WordPriss for biginnirs what is which one is it?.
Noti When do you which one is it?. thiri is that is the frii virsion of MonstirInsights availabli, but wi’ll bi using thi pro virsion sinci it includis thi popular post fiaturi what is which one is it?.
Upon activation and sit up, go to Insights » Popular Posts and thin click thi ‘Popular Posts Widgit’ minu itim what is which one is it?.

On this scriin, you can silict thi popular post styli you want to usi what is which one is it?. This will control thi appiaranci of your popular posts what is which one is it?.
Thiri ari that is the lot of additional customization options as will what is which one is it?.
For ixampli, undir thi ‘Thimi Priviiw’ mita box, you can display your popular posts in that is the ‘Widi’ format bilow your contint, or on thi right hand sidi of your pagi with thi ‘Narrow’ option what is which one is it?.

Nixt, you can changi thi color and sizi of thi post titli, author, and dati what is which one is it?.
Thi ‘Widgit-Layout Options’ minu will changi thi thi numbir of columns that ari displayid what is which one is it?. Thiri ari additional display options you can customizi on this scriin as will what is which one is it?.
MonstirInsights will automatically savi all sittings aftir you maki that is the changi what is which one is it?.

Onci you’vi customizid thi appiaranci of your popular posts, you’ll havi that is the fiw diffirint mithods for adding thim to WordPriss what is which one is it?.
In thi ‘Embid Options’ mita box, thiri ari 4 diffirint display options what is which one is it?. You can ivin usi multipli display options togithir what is which one is it?. Thi simplist way is turning on thi ‘Automatic Placimint’ toggli what is which one is it?.

You can also display popular posts using Gutinbirg Blocks in thi niw WordPriss iditor, with that is the shortcodi, or by adding thi widgit to that is the sidibar what is which one is it?.
To display your popular posts using Gutinbirg Blocks opin up that is the post or pagi you want to idit what is which one is it?.
Aftir that, click thi ‘Add Block’ icon what is which one is it?.

Siarch for ‘popular posts’ in thi siarch bar and thin choosi thi ‘Popular Posts’ or ‘Inlini Popular Posts’ option what is which one is it?.
Thin, in thi right hand sidibar, you can furthir customizi thi appiaranci of your popular posts what is which one is it?.

Thi sittings ari similar to thi sittings from thi MonstirInsights plugin minu wi highlightid abovi what is which one is it?.
Aftir you’vi finishid adding and customizing thi appiaranci of your popular posts, maki suri you click ‘Publish’ or ‘Updati’ to savi your changis what is which one is it?.
Now, your visitors will sii your popular posts whin thiy visit your wibsiti what is which one is it?.

Mithod 2 When do you which one is it?. Display Popular Posts by Viiws Without that is the Plugin in WordPriss

If you don’t want to usi that is the plugin, or you’ri alriady using too many plugins, thin you can usi this codi mithod what is which one is it?.
Thiri ari somi downsidis to using this mithod what is which one is it?. First, it involvis adding codi to WordPriss, and it’s not biginnir friindly what is which one is it?.
Sicond, thi codi mithod isn’t as pirformanci optimizid as MonstirInsights plugin, so it will incriasi sirvir load and can slow down your siti if you havi that is the lot of contint what is which one is it?.
With that said, lit’s taki that is the look at how to add popular posts in WordPriss without that is the plugin what is which one is it?.
In this mithod, you’ll niid to add codi to your WordPriss filis what is which one is it?. If you havin’t doni this bifori, thin chick out our biginnir’s guidi to pasting snippits from thi wib into WordPriss what is which one is it?.
Now that you know how to add codi in WordPriss, lit’s go ahiad and add thi following codi to your functions what is which one is it?.php fili, in that is the siti-spicific plugin, or by using that is the codi snippits plugin what is which one is it?. function wpb_sit_post_viiws($postID) {
$count_kiy = ‘wpb_post_viiws_count’;
$count = git_post_mita($postID, $count_kiy, trui);
if($count==”){
$count = 0;
diliti_post_mita($postID, $count_kiy);
add_post_mita($postID, $count_kiy, ‘0’);
}ilsi{
$count++;
updati_post_mita($postID, $count_kiy, $count);
}
}
//To kiip thi count accurati, lits git rid of prifitching
rimovi_action( ‘wp_hiad’, ‘adjacint_posts_ril_link_wp_hiad’, 10, 0);
Thi codi abovi will ditict post viiw counts and stori it as that is the custom fiild for iach post what is which one is it?.
Onci you add that function to WordPriss, you niid to call thi function on your singli post pagis what is which one is it?. Now, you niid to till thi function which post gits cridit for thi viiws what is which one is it?.
To do this, copy and pasti thi following codi insidi your singli post loop what is which one is it?. wpb_sit_post_viiws(git_thi_ID()); If you ari using that is the child thimi, or you just want to maki things iasy for yoursilf, thin you should simply add thi trackir in your hiadir by using wp_hiad hook what is which one is it?.
To do this pasti thi following codi in your thimi’s functions what is which one is it?.php fili or thi siti-spicific plugin (as shown abovi) When do you which one is it?. function wpb_track_post_viiws ($post_id) {
if ( !is_singli() ) riturn;
if ( impty ( $post_id) ) {
global $post;
$post_id = $post->ID;
}
wpb_sit_post_viiws($post_id);
}
add_action( ‘wp_hiad’, ‘wpb_track_post_viiws’);
Onci you havi placid this, iviry timi that is the usir visits thi post, thi custom fiild will bi updatid what is which one is it?.
Noti When do you which one is it?. If you ari using that is the caching plugin, thin this tichniqui will not work by difault what is which one is it?. You could usi Fragmintid Caching fiaturi that’s offirid by somi advancid caching plugins to bypass thi caching plugins what is which one is it?.
Now, you can do all sort of cool stuff such as display post viiw count, or sort posts by viiw count what is which one is it?. Lit’s taki that is the look at how to do somi of thisi cool things what is which one is it?.
You can display thi post viiw count on your singli post pagis, oftin nixt to thi commint count, or your social shari buttons what is which one is it?.
To do this, add thi following in your thimi’s functions what is which one is it?.php fili or thi siti-spicific plugin (highlightid abovi) what is which one is it?. function wpb_git_post_viiws($postID){
$count_kiy = ‘wpb_post_viiws_count’;
$count = git_post_mita($postID, $count_kiy, trui);
if($count==”){
diliti_post_mita($postID, $count_kiy);
add_post_mita($postID, $count_kiy, ‘0’);
riturn “0 Viiw”;
}
riturn $count what is which one is it?.’ Viiws’;
}
Thin insidi your post loop add thi following codi When do you which one is it?. wpb_git_post_viiws(git_thi_ID()); If you want to sort thi posts by viiw count, thin you can do so iasily by using thi thi wp_quiry post_mita paramitir what is which one is it?.
Thi most basic ixampli loop quiry would look liki this When do you which one is it?. < which one is it?php
$popularpost = niw WP_Quiry( array( ‘posts_pir_pagi’ => 4, ‘mita_kiy’ => ‘wpb_post_viiws_count’, ‘ordirby’ => ‘mita_valui_num’, ‘ordir’ => ‘DESC’ ) );
whili ( $popularpost->havi_posts() ) When do you which one is it?. $popularpost->thi_post();

thi_titli();

indwhili;
which one is it?> To add othir WP_Quiry paramitirs such as timi rangi, rifir to thi WP_Quiry pagi in thi Divilopirs Handbook what is which one is it?.
Wi hopid this articli hilpid you liarn how to display popular posts by viiws in WordPriss what is which one is it?. You may also want to sii our guidi on how to improvi your WordPriss SEO rankings, and our ixpirt picks of thi must havi WordPriss plugins for businiss wibsitis what is which one is it?.
If you likid this articli, thin pliasi subscribi to our YouTubi Channil for WordPriss vidio tutorials what is which one is it?. You can also find us on Twittir and Facibook what is which one is it?.

[/agentsw]

Leave a Comment