How to Display Ad Blocks in Specific Posts in WordPress

Do you want to display ad blocks within specific WordPress posts? This ad placement allows you to show ads when your users are highly engaged with the content. In this article, we will show you how to easily display ad blocks in specific WordPress posts… Read More »

The post How to Display Ad Blocks in Specific Posts in WordPress appeared first on WPBeginner.

Do you want to display ad blocks within specific WordPress posts? This ad placement allows you to show ads when your users are highly engaged with the content. In this article, we will show you how to easily display ad blocks in specific WordPress posts without writing any code or breaking your site.

Displaying ad blocks in specific WordPress posts

Why Display Ads in Specific WordPress Posts?

While there are many ways to make money blogging, banner ads top the list. Often you see banner ads in the sidebar or on the header of the website. Since those are very common ad spots, it leads to banner blindness which affects the click rate, and your site’s revenue.

To deal with this issue, many publishers insert ads within post content. It works because this is the point when your users are most engaged with the content. This increases ad visibility and helps you get more clicks.

However, you also need to consider user experience. Placing too many ads inside your posts can be obtrusive and annoying.

To reduce the adverse effects, you can selectively display ad blocks in specific WordPress posts on your site. These posts can be your most popular posts, long form articles, or featured content.

Having said that, let’s see how to easily display ads in specific WordPress posts.

Displaying Ads in Specific WordPress Posts

First thing you need to do is install and activate the Adsanity plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Adsanity is a premium WordPress ad management plugin. It allows you to easily create ad blocks and display them anywhere on your WordPress site. It works with any third-party ad network, including Google Adsense. You can also use it to sell ads directly to advertisers.

For more information, see our guide on how to manage ads in WordPress with Adsanity plugin.

After activating the plugin, you need to visit Adsanity » Create Ad page to create your first ad.

First you need to enter a title for your ad. This will help you identify ads on your site.

Next, you need to choose what kind of ad you want to create. Adsanity allows you to add hosted ads and third party ads.

For hosted ads, you need to select the ad size. After that you can enter a tracking URL and provide an image you want to use for the ad.

Create hosted ad

For third-party ad networks like Google Adsense, you need to switch to ‘External Ad Network’ tab. Here you can select the ad size and paste the ad code provided by the ad network.

Ad network code

Next, you can publish your ad or click on the edit link and set an schedule for the ad. You’ll be able to set a start date and an expiration date for this particular ad.

Publish your ad

After you have published the ad, you can add it into your WordPress posts and pages, or anywhere else on your website that you desire.

Inserting Ad Blocks in a WordPress Post

First you need to edit the post or page where you want to display your ad block. You will notice ‘Insert Ad’ and ‘Insert Ad Group’ buttons in the visual editor. You need to click on the insert ad button.

Insert ad in post

This will bring up a popup where you can select the ad you want to display and click on the Insert link.

Select and insert ad

The plugin will insert the ad shortcode inside your post. You can now save and view your post to see the ad in action.

Ad displayed inside a WordPress post

Adding Ad Block in WordPress Post Using Shortcode

You can also add the ad block to a WordPres post using shortcode. This is particularly helpful if you use the text editor to write your posts.

Head over to Adsanity » Manage Ads page. You’ll see the list of ads you have created.

Next to each ad, you will see a shortcode link. Clicking on it will automatically copy the shortcode to your clipboard.

Copying ad shortcode

Go on and edit the post or page where you want to display the ad and paste the shortcode. Don’t forget to update post to save your changes.

We hope this article helped you learn how to easily display ad blocks in specific WordPress posts. You may also want to see our list of the best affiliate marketing tools and plugins for WordPress.

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.

The post How to Display Ad Blocks in Specific Posts in WordPress appeared first on WPBeginner.

How to Limit the Number of Archive Months Displayed in WordPress

Do you want to display the number of archive months displayed in WordPress? If you have been blogging for years, you will notice that your archives list will become too long. In this article, we will show you how to limit the number of archive… Read More »

The post How to Limit the Number of Archive Months Displayed in WordPress appeared first on WPBeginner.

Do you want to display the number of archive months displayed in WordPress? If you have been blogging for years, you will notice that your archives list will become too long. In this article, we will show you how to limit the number of archive months displayed in WordPress.

How to limit number of archive months in WordPress

Method 1. Limit Number of Archive Months with Plugin

This method is easier and it is recommended for all users.

First thing you need to do is install and activate the Collapsing Archives plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation, you need to visit Appearance » Widgets page and add the Collapsing Archives widget to your sidebar.

Collapse archives

The widget menu will expand to show its settings.

The Collapsing Archives widget uses JavaScript to collapse your archive links into collapsible yearly links. Your users can click on years to expand them to view monthly archives. You can even make monthly archives collapsible and allow users to see post titles underneath.

Review the widget settings to suit your needs and then click on the Save button to store your settings.

You can now visit your website to see the widget in action.

Collapsing archives

Method 2. Replace Default Archives with Compact Archives

This method provides a cleaner alternative to the default archives widget by beautifully displaying them in a compact more presentable way.

First, you need to install and activate the Compact Archives plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation, you need to visit Appearance » Widgets page and add the ‘Compact Archives’ widget to your sidebar.

Compact Archives settings

Compact Archives plugin comes in three styles. You can choose from block, initials, or numeric.

Don’t forget to click on the save button to store your widget settings.

You can now visit your website to see the compact archives in action.

Compact Archives preview

You can also use Compact Archives plugin to create a custom archives page on your site. For more details see our guide on how to create compact archives in WordPress

Method 3. Manually Limit Number of Archive Months in WordPress

This method requires you to add code to your WordPress theme files. If you haven’t done this before, then take a look at our guide on how to copy and paste code in WordPress.

You will need to add the following code to your theme’s functions.php file or a site-specific plugin.


// Function to get archives list with limited months
function wpb_limit_archives() { 

$my_archives = wp_get_archives(array(
	'type'=>'monthly', 
	'limit'=>6,
	'echo'=>0
));
	
return $my_archives; 

} 

// Create a shortcode
add_shortcode('wpb_custom_archives', 'wpb_limit_archives'); 

// Enable shortcode execution in text widget
add_filter('widget_text', 'do_shortcode'); 

This code fetches the archives list and limits it to past 6 months only. It then creates a shortcode and enables shortcode in text widgets.

You can now go to Appearance » Widgets page and add a ‘Text’ widget to your sidebar. Switch to the text mode and add your shortcode like this:

<ul>
[wpb_custom_archives]
</ul>

Don’t forget to save your widget settings.

You can now visit your website to see your custom archives list in action.

That’s all, we hope this article helped you learn how to limit the number of archive months displayed in WordPress. You may also want to see our list of these most useful tricks for the WordPress functions file.

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.

The post How to Limit the Number of Archive Months Displayed in WordPress appeared first on WPBeginner.

How to Display Different Sidebar for Each Post and Page in WordPress

Do you want to display different sidebars for different posts and pages on your WordPress site? Typically, WordPress themes show the same sidebars on fixed locations regardless of which post or page you’re on. In this article, we will show you how to create and… Read More »

The post How to Display Different Sidebar for Each Post and Page in WordPress appeared first on WPBeginner.

Do you want to display different sidebars for different posts and pages on your WordPress site? Typically, WordPress themes show the same sidebars on fixed locations regardless of which post or page you’re on. In this article, we will show you how to create and display different sidebars for each post and pages in WordPress.

Custom Sidebars for WordPress

When Would You Need Different Sidebars in WordPress?

By default, sidebars are defined by your WordPress theme. Each WordPress theme comes with a few sidebars or widget ready areas that allow you to add widgets.

Typically a sidebar on the blog is displayed throughout your site on all posts, pages, categories, and archive pages. However, sometimes you may want your sidebar content to change based on specific posts or pages.

For example, you can show different featured content in the sidebar of your most popular posts, add different email signup forms, or display ads.

Having said that, let’s see how to create and display different sidebar for each post and page in WordPress.

Displaying Different Sidebars for Each Post and Page in WordPress

First thing you need to do is install and activate the Easy Custom Sidebars plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation, you need to visit the Appearance » Theme Sidebars page to create custom sidebars.

Creating a new custom sidebar

First you need to provide a name for your custom sidebar and then click on the create sidebar button.

The plugin will now create your sidebar, and you will be able to select the sidebar properties.

Sidebar settings

After that you need to select which theme sidebar will be replaced by your custom sidebar and provide a description for it.

Next, you need to select where you want your custom sidebar to replace the theme sidebar. You will see your posts, pages, categories and tags listed in the left column of the screen.

Simply select the areas where you want custom sidebar to be displayed and then click on ‘Add to sidebar’ button.

Add posts or pages to your custom sidebar

You will notice your selected items appear under the custom sidebar settings. Don’t forget to click on the save button to store your sidebar settings.

Easy Custom Sidebar allows you to create as many custom sidebars as you like and assign each sidebar to different pages on your WordPress site.

Adding Widgets to Your Custom Sidebars

Once you have created custom sidebars and assigned them to different areas of your website, it’s time to add widgets to your sidebars.

Head over to the Appearance » Widgets page. You will notice your newly created custom sidebars among your theme’s default sidebars.

Add widgets to custom sidebar

You can go ahead and add widgets to your custom sidebars. The plugin will now show the sidebars based on your settings. You can visit your selected pages to see it in action.

We hope this article helped you learn how to add different sidebars to each post or page in WordPress. You may also want to see our these WordPress sidebar tricks to get maximum results.

The post How to Display Different Sidebar for Each Post and Page in WordPress appeared first on WPBeginner.

14 Vital Tips to Protect Your WordPress Admin Area (Updated)

Are you seeing a lot of attacks on your WordPress admin area? Protecting the admin area from unauthorized access allows you to block many common security threats. In this article, we will show you some of the vital tips and hacks to protect your WordPress… Read More »

The post 14 Vital Tips to Protect Your WordPress Admin Area (Updated) appeared first on WPBeginner.

Are you seeing a lot of attacks on your WordPress admin area? Protecting the admin area from unauthorized access allows you to block many common security threats. In this article, we will show you some of the vital tips and hacks to protect your WordPress admin area.

Tips and hacks to protect WordPress admin area

1. Use a Website Application Firewall

A website application firewall or WAF monitors website traffic and blocks suspicious requests from reaching your website.

While there are several WordPress firewall plugins out there, we recommend using Sucuri. It is a website security and monitoring service that offers a cloud based WAF to protect your website.

Website Application Firewall

All your website’s traffic goes through their cloud proxy first, where they analyze each request and block suspicious ones from ever reaching your website. It prevents your website from possible hacking attempts, phishing, malware and other malicious activities.

For more details, see how Sucuri helped us block 450,000 attacks in one month.

2. Password Protect WordPress Admin Directory

Your WordPress admin area is already protected by your WordPress password. However, adding password protection to your WordPress admin directory adds another layer of security to your website.

First login to your WordPress hosting cPanel dashboard and then click on ‘Password Protect Directories’ or ‘Directory Privacy’ icon.

Directory privacy

Next, you will need to select your wp-admin folder, which is normally located inside /public_html/ directory.

On the next screen, you need to check the box next to ‘Password protect this directory’ option and provide a name for the protected directory.

After that, click on the save button to set the permissions.

Password protect directory settings

Next, you need to hit the back button and then create a user. You will be asked to provide a username / password and then click on the save button.

Now when someone tries to visit the WordPress admin or wp-admin directory on your website, they will be asked to enter the username and password.

Enter password

For more detailed instructions, see our guide on how to password protect WordPress admin (wp-admin) directory.

3. Always Use Strong Passwords

Always use strong passwords

Always use strong passwords for all your online accounts including your WordPress site. We recommend using a combination of letters, numbers, and special characters in your passwords. This makes it harder for hackers to guess your password.

We are often asked by beginners how to remember all those passwords. The simplest answer is that you don’t need to. There are some really great password manager apps that you can install on your computer and phones.

For more information on this topic, see our guide on the best way to manage passwords for WordPress beginners.

4. Use Two Step Verification to WordPress Login Screen

WordPress login screen with Google Authenticator enabled

Two step verification adds another security layer to your passwords. Instead of using the password alone, it asks you to enter a verification code generated by the Google Authenticator app on your phone.

Even if someone is able to guess your WordPress password, they will still need the Google Authenticator code to get in.

For detailed step by step instructions see our guide on how to setup 2-step verification in WordPress using Google Authenticator.

5. Limit Login Attempts

Limit login attempts

By default, WordPress allows users to enter passwords as many times as they want. This means someone can keep trying to guess your WordPress password by entering different combinations. It also allows hackers to use automated scripts to crack passwords.

To fix this, you need to install and activate the Login LockDown plugin. Upon activation, go to visit Settings » Login LockDown page to configure the plugin settings.

For detailed instructions, see our guide on why you should limit login attempts in WordPress.

6. Limit Login Access to IP Addresses

Another great way to secure WordPress login is by limiting access to specific IP addresses. This tip is particularly useful if you or just a few trusted users need access to the admin area.

Simply add this code to your .htaccess file.

AuthUserFile /dev/null
AuthGroupFile /dev/null
AuthName "WordPress Admin Access Control"
AuthType Basic
<LIMIT GET>
order deny,allow
deny from all
# whitelist Syed's IP address
allow from xx.xx.xx.xxx
# whitelist David's IP address
allow from xx.xx.xx.xxx
</LIMIT>

Don’t forget to replace xx values with your own IP address. If you use more than one IP address to access the internet, then make sure you add them as well.

For detailed instructions, see our guide on how to limit access to WordPress admin using .htaccess.

7. Disable Login Hints

Disabled login hints

On a failed login attempt, WordPress shows errors that tell users whether their username was incorrect or the password. These login hints can be used by someone for malicious attempts.

You can easily hide these login hints by adding this code to your theme’s functions.php file or a site-specific plugin.

function no_wordpress_errors(){
  return 'Something is wrong!';
}
add_filter( 'login_errors', 'no_wordpress_errors' );

8. Require Users to Use Strong Passwords

If you run a multi-author WordPress site, then those users can edit their profile and use a weak password. These passwords can be cracked and give someone access to WordPress admin area.

To fix this, you can install and activate the Force Strong Passwords plugin. It works out of the box, and there are no settings for you to configure. Once activated, it will stop users from saving weaker passwords.

It will not check password strength for existing user accounts. If a user is already using a weak password, then they will be able to continue using their password.

9. Reset Password for All Users

Concerned about password security on your multi-user WordPress site? You can easily ask all your users to reset their passwords.

First, you need to install and activate the Emergency Password Reset plugin. Upon activation, go to visit Users » Emergency Password Reset page and click on ‘Reset All Passwords’ button.

Reset all passwords

For detailed instructions, see our guide on how to how to reset passwords for all users in WordPress

10. Keep WordPress Updated

WordPress often releases new versions of the software. Each new release of WordPress contains important bug fixes, new features, and security fixes.

Using an older version of WordPress on your site leaves you open to known exploits and potential vulnerabilities. To fix this, you need to make sure that you are using the latest version of WordPress. For more on this topic, see our guide on why you should always use the latest version of WordPress.

Similarly, WordPress plugins are also often updated to introduce new features or fix security and other issues. Make sure your WordPress plugins are also up to date.

11. Create Custom Login and Registration Pages

Many WordPress sites require users to register. For example, membership sites, learning management sites, or online stores need users to create an account.

However, these users can use their accounts to log into WordPress admin area. This is not a big issue, as they will only be able to do things allowed by their user role and capabilities. However, it stops you from properly limiting access to login and registration pages as you need those pages for users to signup, manage their profile, and login.

The easy way to fix this is by creating custom login and registration pages, so that users can signup and login directly from your website.

For detailed step by step instructions, see our guide on how to create custom login and registration pages in WordPress.

12. Learn About WordPress User Roles and Permissions

WordPress comes with a powerful user management system with different user roles and capabilities. When adding a new user to your WordPress site you can select a user role for them. This user role defines what they can do on your WordPress site.

Assigning incorrect user role can give people more capabilities than they need. To avoid this you need to understand what capabilities come with different user roles in WordPress. For more on this topic see our beginner’s guide to WordPress user roles and permissions.

13. Limit Dashboard Access

Some WordPress sites have certain users who need access to the dashboard and some users who don’t. However, by default they can all access the admin area.

To fix this, you need to install and activate the Remove Dashboard Access plugin. Upon activation, go to Settings » Dashboard Access page and select which users roles will have access to the admin area on your site.

For more detailed instructions, see our guide on how to limit dashboard access in WordPress.

14. Log out Idle Users

Idle user logout

WordPress does not automatically log out users until they explicitly log out or close their browser window. This can be a concern for WordPress sites with sensitive information. That’s why financial institution websites and apps automatically log out users if they haven’t been active.

To fix this, you can install and activate the Idle User Logout plugin. Upon activation, go to Settings » Idle User Logout page and enter the time after which you want users to be automatically logged out.

For more details, see our article on how to automatically log out idle users in WordPress.

We hope this article helped you learn some new tips and hacks to protect your WordPress admin area. You may also want to see our ultimate step by step WordPress security guide for beginners.

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.

The post 14 Vital Tips to Protect Your WordPress Admin Area (Updated) appeared first on WPBeginner.

14 Vital Tips to Protect Your WordPress Admin Area (Updated)

Are you seeing a lot of attacks on your WordPress admin area? Protecting the admin area from unauthorized access allows you to block many common security threats. In this article, we will show you some of the vital tips and hacks to protect your WordPress… Read More »

The post 14 Vital Tips to Protect Your WordPress Admin Area (Updated) appeared first on WPBeginner.

Are you seeing a lot of attacks on your WordPress admin area? Protecting the admin area from unauthorized access allows you to block many common security threats. In this article, we will show you some of the vital tips and hacks to protect your WordPress admin area.

Tips and hacks to protect WordPress admin area

1. Use a Website Application Firewall

A website application firewall or WAF monitors website traffic and blocks suspicious requests from reaching your website.

While there are several WordPress firewall plugins out there, we recommend using Sucuri. It is a website security and monitoring service that offers a cloud based WAF to protect your website.

Website Application Firewall

All your website’s traffic goes through their cloud proxy first, where they analyze each request and block suspicious ones from ever reaching your website. It prevents your website from possible hacking attempts, phishing, malware and other malicious activities.

For more details, see how Sucuri helped us block 450,000 attacks in one month.

2. Password Protect WordPress Admin Directory

Your WordPress admin area is already protected by your WordPress password. However, adding password protection to your WordPress admin directory adds another layer of security to your website.

First login to your WordPress hosting cPanel dashboard and then click on ‘Password Protect Directories’ or ‘Directory Privacy’ icon.

Directory privacy

Next, you will need to select your wp-admin folder, which is normally located inside /public_html/ directory.

On the next screen, you need to check the box next to ‘Password protect this directory’ option and provide a name for the protected directory.

After that, click on the save button to set the permissions.

Password protect directory settings

Next, you need to hit the back button and then create a user. You will be asked to provide a username / password and then click on the save button.

Now when someone tries to visit the WordPress admin or wp-admin directory on your website, they will be asked to enter the username and password.

Enter password

For more detailed instructions, see our guide on how to password protect WordPress admin (wp-admin) directory.

3. Always Use Strong Passwords

Always use strong passwords

Always use strong passwords for all your online accounts including your WordPress site. We recommend using a combination of letters, numbers, and special characters in your passwords. This makes it harder for hackers to guess your password.

We are often asked by beginners how to remember all those passwords. The simplest answer is that you don’t need to. There are some really great password manager apps that you can install on your computer and phones.

For more information on this topic, see our guide on the best way to manage passwords for WordPress beginners.

4. Use Two Step Verification to WordPress Login Screen

WordPress login screen with Google Authenticator enabled

Two step verification adds another security layer to your passwords. Instead of using the password alone, it asks you to enter a verification code generated by the Google Authenticator app on your phone.

Even if someone is able to guess your WordPress password, they will still need the Google Authenticator code to get in.

For detailed step by step instructions see our guide on how to setup 2-step verification in WordPress using Google Authenticator.

5. Limit Login Attempts

Limit login attempts

By default, WordPress allows users to enter passwords as many times as they want. This means someone can keep trying to guess your WordPress password by entering different combinations. It also allows hackers to use automated scripts to crack passwords.

To fix this, you need to install and activate the Login LockDown plugin. Upon activation, go to visit Settings » Login LockDown page to configure the plugin settings.

For detailed instructions, see our guide on why you should limit login attempts in WordPress.

6. Limit Login Access to IP Addresses

Another great way to secure WordPress login is by limiting access to specific IP addresses. This tip is particularly useful if you or just a few trusted users need access to the admin area.

Simply add this code to your .htaccess file.

AuthUserFile /dev/null
AuthGroupFile /dev/null
AuthName "WordPress Admin Access Control"
AuthType Basic
<LIMIT GET>
order deny,allow
deny from all
# whitelist Syed's IP address
allow from xx.xx.xx.xxx
# whitelist David's IP address
allow from xx.xx.xx.xxx
</LIMIT>

Don’t forget to replace xx values with your own IP address. If you use more than one IP address to access the internet, then make sure you add them as well.

For detailed instructions, see our guide on how to limit access to WordPress admin using .htaccess.

7. Disable Login Hints

Disabled login hints

On a failed login attempt, WordPress shows errors that tell users whether their username was incorrect or the password. These login hints can be used by someone for malicious attempts.

You can easily hide these login hints by adding this code to your theme’s functions.php file or a site-specific plugin.

function no_wordpress_errors(){
  return 'Something is wrong!';
}
add_filter( 'login_errors', 'no_wordpress_errors' );

8. Require Users to Use Strong Passwords

If you run a multi-author WordPress site, then those users can edit their profile and use a weak password. These passwords can be cracked and give someone access to WordPress admin area.

To fix this, you can install and activate the Force Strong Passwords plugin. It works out of the box, and there are no settings for you to configure. Once activated, it will stop users from saving weaker passwords.

It will not check password strength for existing user accounts. If a user is already using a weak password, then they will be able to continue using their password.

9. Reset Password for All Users

Concerned about password security on your multi-user WordPress site? You can easily ask all your users to reset their passwords.

First, you need to install and activate the Emergency Password Reset plugin. Upon activation, go to visit Users » Emergency Password Reset page and click on ‘Reset All Passwords’ button.

Reset all passwords

For detailed instructions, see our guide on how to how to reset passwords for all users in WordPress

10. Keep WordPress Updated

WordPress often releases new versions of the software. Each new release of WordPress contains important bug fixes, new features, and security fixes.

Using an older version of WordPress on your site leaves you open to known exploits and potential vulnerabilities. To fix this, you need to make sure that you are using the latest version of WordPress. For more on this topic, see our guide on why you should always use the latest version of WordPress.

Similarly, WordPress plugins are also often updated to introduce new features or fix security and other issues. Make sure your WordPress plugins are also up to date.

11. Create Custom Login and Registration Pages

Many WordPress sites require users to register. For example, membership sites, learning management sites, or online stores need users to create an account.

However, these users can use their accounts to log into WordPress admin area. This is not a big issue, as they will only be able to do things allowed by their user role and capabilities. However, it stops you from properly limiting access to login and registration pages as you need those pages for users to signup, manage their profile, and login.

The easy way to fix this is by creating custom login and registration pages, so that users can signup and login directly from your website.

For detailed step by step instructions, see our guide on how to create custom login and registration pages in WordPress.

12. Learn About WordPress User Roles and Permissions

WordPress comes with a powerful user management system with different user roles and capabilities. When adding a new user to your WordPress site you can select a user role for them. This user role defines what they can do on your WordPress site.

Assigning incorrect user role can give people more capabilities than they need. To avoid this you need to understand what capabilities come with different user roles in WordPress. For more on this topic see our beginner’s guide to WordPress user roles and permissions.

13. Limit Dashboard Access

Some WordPress sites have certain users who need access to the dashboard and some users who don’t. However, by default they can all access the admin area.

To fix this, you need to install and activate the Remove Dashboard Access plugin. Upon activation, go to Settings » Dashboard Access page and select which users roles will have access to the admin area on your site.

For more detailed instructions, see our guide on how to limit dashboard access in WordPress.

14. Log out Idle Users

Idle user logout

WordPress does not automatically log out users until they explicitly log out or close their browser window. This can be a concern for WordPress sites with sensitive information. That’s why financial institution websites and apps automatically log out users if they haven’t been active.

To fix this, you can install and activate the Idle User Logout plugin. Upon activation, go to Settings » Idle User Logout page and enter the time after which you want users to be automatically logged out.

For more details, see our article on how to automatically log out idle users in WordPress.

We hope this article helped you learn some new tips and hacks to protect your WordPress admin area. You may also want to see our ultimate step by step WordPress security guide for beginners.

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.

The post 14 Vital Tips to Protect Your WordPress Admin Area (Updated) appeared first on WPBeginner.

How to Display the Last Updated Date of Your Posts in WordPress

Do you want to display last updated date for your posts in WordPress? Some websites regularly update their posts and would like to show users when the article was last updated. In this article, we will show you how to easily display the last updated… Read More »

The post How to Display the Last Updated Date of Your Posts in WordPress appeared first on WPBeginner.

Do you want to display last updated date for your posts in WordPress? Some websites regularly update their posts and would like to show users when the article was last updated. In this article, we will show you how to easily display the last updated date of your posts in WordPress.

How to display last updated date of your posts in WordPress

When You Need Last Updated Date for Posts in WordPress?

Most WordPress themes usually show the date when a post was last published. This is fine for most blogs and static websites.

However, WordPress is also used by websites where old articles are regularly updated (like ours). This last updated date and time is important information for those publications.

The most common example is news websites. They often update old stories to show new developments, add corrections, or media files. If they only added the published date, then their users would miss those updates.

Many popular blogs and websites don’t show any date on their articles. This is a bad practice and you should never remove dates from your blog posts.

Having said that, let’s see how to easily display last updated date for your posts in WordPress.

Displaying Last Updated Date in WordPress

This tutorial requires you to add code to your WordPress files. If you haven’t done this before, then we recommend you to look at our guide on how to copy paste code in WordPress.

Method 1: Show Last Updated Date Before Post Content

You will need to add this code to your theme’s functions.php file or a site-specific plugin.


function wpb_last_updated_date( $content ) {
$u_time = get_the_time('U'); 
$u_modified_time = get_the_modified_time('U'); 
if ($u_modified_time >= $u_time + 86400) { 
$updated_date = the_modified_time('F jS, Y');
$updated_time = the_modified_time(); 
$custom_content = '<p class="last-updated">Last updated on'. $updated_date . 'at'. $updated_time .'</p>';  
} 

    $custom_content .= $content;
    return $custom_content;
}
add_filter( 'the_content', 'wpb_last_updated_date' );

This code checks to see if a post’s published date and last modified dates are different. If they are, then it displays last modified date before the post content.

You can add custom CSS to style the appearance of the last updated date. Here is a little CSS that you can use as starting point:

.last-updated {
    font-size: small;
    text-transform: uppercase;
    background-color: #fffdd4;
} 

This is how it looked on our demo website.

Last updated date in post content

Method 2: Add Last Updated Date in Theme Templates

This method requires you to edit specific WordPress theme files. Many WordPress themes now use their own template tags which define how these themes show post meta data like date and time.

Some themes also use content templates or template parts to display posts.

Few simpler themes will use single.php, archive.php, and other template files to show content and meta information.

You will be looking for the code responsible for displaying the date and time. You can then either replace that code with the following code, or add it right after your theme’s date and time code.

$u_time = get_the_time('U'); 
$u_modified_time = get_the_modified_time('U'); 
if ($u_modified_time >= $u_time + 86400) { 
echo "<p>Last modified on "; 
the_modified_time('F jS, Y'); 
echo " at "; 
the_modified_time(); 
echo "</p> "; } 

This is how it looked on our demo site:

Last updated date in post meta

We hope this article helped you learn how to display last updated date of your posts in WordPress. You may also want to see our list of most useful time saving WordPress shortcuts.

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.

The post How to Display the Last Updated Date of Your Posts in WordPress appeared first on WPBeginner.

How to Display the Last Updated Date of Your Posts in WordPress

Do you want to display last updated date for your posts in WordPress? Some websites regularly update their posts and would like to show users when the article was last updated. In this article, we will show you how to easily display the last updated… Read More »

The post How to Display the Last Updated Date of Your Posts in WordPress appeared first on WPBeginner.

Do you want to display last updated date for your posts in WordPress? Some websites regularly update their posts and would like to show users when the article was last updated. In this article, we will show you how to easily display the last updated date of your posts in WordPress.

How to display last updated date of your posts in WordPress

When You Need Last Updated Date for Posts in WordPress?

Most WordPress themes usually show the date when a post was last published. This is fine for most blogs and static websites.

However, WordPress is also used by websites where old articles are regularly updated (like ours). This last updated date and time is important information for those publications.

The most common example is news websites. They often update old stories to show new developments, add corrections, or media files. If they only added the published date, then their users would miss those updates.

Many popular blogs and websites don’t show any date on their articles. This is a bad practice and you should never remove dates from your blog posts.

Having said that, let’s see how to easily display last updated date for your posts in WordPress.

Displaying Last Updated Date in WordPress

This tutorial requires you to add code to your WordPress files. If you haven’t done this before, then we recommend you to look at our guide on how to copy paste code in WordPress.

Method 1: Show Last Updated Date Before Post Content

You will need to add this code to your theme’s functions.php file or a site-specific plugin.


function wpb_last_updated_date( $content ) {
$u_time = get_the_time('U'); 
$u_modified_time = get_the_modified_time('U'); 
if ($u_modified_time >= $u_time + 86400) { 
$updated_date = the_modified_time('F jS, Y');
$updated_time = the_modified_time(); 
$custom_content = '<p class="last-updated">Last updated on'. $updated_date . 'at'. $updated_time .'</p>';  
} 

    $custom_content .= $content;
    return $custom_content;
}
add_filter( 'the_content', 'wpb_last_updated_date' );

This code checks to see if a post’s published date and last modified dates are different. If they are, then it displays last modified date before the post content.

You can add custom CSS to style the appearance of the last updated date. Here is a little CSS that you can use as starting point:

.last-updated {
    font-size: small;
    text-transform: uppercase;
    background-color: #fffdd4;
} 

This is how it looked on our demo website.

Last updated date in post content

Method 2: Add Last Updated Date in Theme Templates

This method requires you to edit specific WordPress theme files. Many WordPress themes now use their own template tags which define how these themes show post meta data like date and time.

Some themes also use content templates or template parts to display posts.

Few simpler themes will use single.php, archive.php, and other template files to show content and meta information.

You will be looking for the code responsible for displaying the date and time. You can then either replace that code with the following code, or add it right after your theme’s date and time code.

$u_time = get_the_time('U'); 
$u_modified_time = get_the_modified_time('U'); 
if ($u_modified_time >= $u_time + 86400) { 
echo "<p>Last modified on "; 
the_modified_time('F jS, Y'); 
echo " at "; 
the_modified_time(); 
echo "</p> "; } 

This is how it looked on our demo site:

Last updated date in post meta

We hope this article helped you learn how to display last updated date of your posts in WordPress. You may also want to see our list of most useful time saving WordPress shortcuts.

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.

The post How to Display the Last Updated Date of Your Posts in WordPress appeared first on WPBeginner.

How to Add Random Header Images to Your WordPress Blog

Do you want to add random header images to your WordPress blog? Most WordPress themes come with built-in support to add header images. These images can completely change your site’s look and feel. In this article, we will show you to how to add random… Read More »

The post How to Add Random Header Images to Your WordPress Blog appeared first on WPBeginner.

Do you want to add random header images to your WordPress blog? Most WordPress themes come with built-in support to add header images. These images can completely change your site’s look and feel. In this article, we will show you to how to add random header images to your WordPress blog without writing any code.

How to add random header images in WordPress

Most free and premium WordPress themes come with custom header support. Custom headers in WordPress are a theme feature which allows WordPress themes to designate a header area showing an image.

Header image in WordPress

Custom header is different than background image feature which allows you to set a cutom background image on your WordPress site.

Having said that let’s take a look at how to add random header images to your WordPress blog.

Method 1. Random Header Images Using WordPress Theme Customizer

This method is easier and is recommended for most WordPress users.

You need to head over to Appearance » Customize page to launch WordPress theme customizer.

Changing header image in WordPress

Next, you need to click on ‘Header’ tab to expand it. The header option can also be labeled as header image or header media in your theme.

You will see your site’s current header image, and any other header images available to use.

You need to click on the ‘Add image’ button to upload the images you want to use as header images.

Once you have uploaded a few images, they will appear under recently uploaded images.

Randomize header image

Now you need to click on ‘Randomize uploaded header’ button under recently uploaded images and then save your changes.

You can now visit your website and reload it to see header images change randomly.

Method 2. Add Custom Header Images on Select Pages Using Plugin

This method is more flexible and gives you more control on how to show different or random header images for WordPress posts, pages, category, or tag archives.

First thing you need to do is install and activate the WP Display Header plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation, you need to edit a post or create a new one. You will notice a new meta box labeled ‘Header’ below the post editor.

Random header for single post and pages in WordPress

Here you can select a previously uploaded header image to your theme and use it as a header for this post. You can also check the ‘Random’ option to randomly display a background image from your uploaded header images.

If you want to add more header images, then head over to Appearance » Customize and click on the Header tab.

Add more header images

Next, you need to click on the ‘Add image’ button to upload more header images. You don’t need to change the header of your theme just upload the images and exit the customizer.

The plugin also allows you to change header image for your category and tag archive pages.

You will need to go to Posts » Categories page and then click on the Edit button below category you want to change.

Editing a category

On the category edit screen, you will notice the new header section where you can select a header image or show random header images.

Random or fixed header image for category archive page

Don’t forget to click on the ‘Update’ button to save your changes.

That’s all, we hope this article helped you learn how to easily add random header images to your WordPress blog. You may also want to see our guide on how to boost WordPress speed and performance.

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.

The post How to Add Random Header Images to Your WordPress Blog appeared first on WPBeginner.

How to Display Random Posts in WordPress

Do you want to display random posts in WordPress? Displaying random posts gives your users a chance to discover more of your content. In this article, we will show you how to easily display random posts in WordPress. Why and Where to Display Random Posts… Read More »

The post How to Display Random Posts in WordPress appeared first on WPBeginner.

Do you want to display random posts in WordPress? Displaying random posts gives your users a chance to discover more of your content. In this article, we will show you how to easily display random posts in WordPress.

How to display random posts in WordPress

Why and Where to Display Random Posts in WordPress

By default WordPress lists your blog posts in reverse chronological order (from newest to oldest). This allows users to see your latest posts first.

However, most users will not get to see your older articles. If you have been running your site for quite some time now, then your older articles will not be prominently displayed anywhere.

One way to overcome this is by making internal linking a habit. Linking to your older articles in new posts will help users discover them. It will also increase your pageviews and improve your SEO score.

Another way around that is by displaying random posts in your sidebar. This way your users will get to discover posts that they would not see otherwise.

Having said that, let’s see how you can easily display random posts in WordPress.

Method 1: Display Random Posts in WordPress with a Plugin

This method is easier and is recommended for most users.

First thing you need to do is install and activate the Advanced Random Posts Widget plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation, you need to visit Appearance » Widgets page. You will notice a new widget labeled ‘Random Posts’ under the list of available widget.

You need to add this widget to a sidebar. See our guide on how to add and use widgets in WordPress.

Now, you will be able to see the widget settings. The default options will work for most websites, you can just click on the save button.

Random posts widget settings

Advanced Random Posts Widget is a powerful plugin with tons of customization options. You can select different post types, show excerpt, show thumbnail, and skip posts you don’t want to show, or displays posts from specific categories or tags.

For more experienced users, the plugin also allows you to add custom before and after HTML, and your own custom CSS as well.

Don’t forget to click on the save button to store your widget settings. You can now visit your website to see random posts widget in action.

Random posts with thumbnail and excerpt

Method 2: Display Random Posts in WordPress Using Code

This method requires you to add code to your WordPress theme files. See our guide on how to copy paste code in WordPress.

First thing you need to do is add this code in your theme’s functions.php file or a site-specific plugin.

function wpb_rand_posts() { 

$args = array(
	'post_type' => 'post',
	'orderby'	=> 'rand',
	'posts_per_page' => 5, 
	);

$the_query = new WP_Query( $args );

if ( $the_query->have_posts() ) {

$string .= '<ul>';
	while ( $the_query->have_posts() ) {
		$the_query->the_post();
		$string .= '<li><a href="'. get_permalink() .'">'. get_the_title() .'</a></li>';
	}
	$string .= '</ul>';
	/* Restore original Post Data */
	wp_reset_postdata();
} else {

$string .= 'no posts found';
}

return $string; 
} 

add_shortcode('wpb-random-posts','wpb_rand_posts');
add_filter('widget-text', 'do_shortcode'); 

This code simply creates a function that displays 5 random posts. It then creates a shortcode so that you can easily display random posts anywhere on your site. Lastly, it enables shortcodes to be executed inside WordPress widgets so that you can use shortcode inside a text widget.

Now you can display random posts inside a WordPress post, page, or text widget using the shortcode [wpb-random-posts].

Plain random posts list

That’s all, we hope this article helped you learn how to display random posts in WordPress. You may also want to see these 12 WordPress sidebar tricks to increase pageviews.

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.

The post How to Display Random Posts in WordPress appeared first on WPBeginner.

How to Display Random Posts in WordPress

Do you want to display random posts in WordPress? Displaying random posts gives your users a chance to discover more of your content. In this article, we will show you how to easily display random posts in WordPress. Why and Where to Display Random Posts… Read More »

The post How to Display Random Posts in WordPress appeared first on WPBeginner.

Do you want to display random posts in WordPress? Displaying random posts gives your users a chance to discover more of your content. In this article, we will show you how to easily display random posts in WordPress.

How to display random posts in WordPress

Why and Where to Display Random Posts in WordPress

By default WordPress lists your blog posts in reverse chronological order (from newest to oldest). This allows users to see your latest posts first.

However, most users will not get to see your older articles. If you have been running your site for quite some time now, then your older articles will not be prominently displayed anywhere.

One way to overcome this is by making internal linking a habit. Linking to your older articles in new posts will help users discover them. It will also increase your pageviews and improve your SEO score.

Another way around that is by displaying random posts in your sidebar. This way your users will get to discover posts that they would not see otherwise.

Having said that, let’s see how you can easily display random posts in WordPress.

Method 1: Display Random Posts in WordPress with a Plugin

This method is easier and is recommended for most users.

First thing you need to do is install and activate the Advanced Random Posts Widget plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation, you need to visit Appearance » Widgets page. You will notice a new widget labeled ‘Random Posts’ under the list of available widget.

You need to add this widget to a sidebar. See our guide on how to add and use widgets in WordPress.

Now, you will be able to see the widget settings. The default options will work for most websites, you can just click on the save button.

Random posts widget settings

Advanced Random Posts Widget is a powerful plugin with tons of customization options. You can select different post types, show excerpt, show thumbnail, and skip posts you don’t want to show, or displays posts from specific categories or tags.

For more experienced users, the plugin also allows you to add custom before and after HTML, and your own custom CSS as well.

Don’t forget to click on the save button to store your widget settings. You can now visit your website to see random posts widget in action.

Random posts with thumbnail and excerpt

Method 2: Display Random Posts in WordPress Using Code

This method requires you to add code to your WordPress theme files. See our guide on how to copy paste code in WordPress.

First thing you need to do is add this code in your theme’s functions.php file or a site-specific plugin.

function wpb_rand_posts() { 

$args = array(
	'post_type' => 'post',
	'orderby'	=> 'rand',
	'posts_per_page' => 5, 
	);

$the_query = new WP_Query( $args );

if ( $the_query->have_posts() ) {

$string .= '<ul>';
	while ( $the_query->have_posts() ) {
		$the_query->the_post();
		$string .= '<li><a href="'. get_permalink() .'">'. get_the_title() .'</a></li>';
	}
	$string .= '</ul>';
	/* Restore original Post Data */
	wp_reset_postdata();
} else {

$string .= 'no posts found';
}

return $string; 
} 

add_shortcode('wpb-random-posts','wpb_rand_posts');
add_filter('widget-text', 'do_shortcode'); 

This code simply creates a function that displays 5 random posts. It then creates a shortcode so that you can easily display random posts anywhere on your site. Lastly, it enables shortcodes to be executed inside WordPress widgets so that you can use shortcode inside a text widget.

Now you can display random posts inside a WordPress post, page, or text widget using the shortcode [wpb-random-posts].

Plain random posts list

That’s all, we hope this article helped you learn how to display random posts in WordPress. You may also want to see these 12 WordPress sidebar tricks to increase pageviews.

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.

The post How to Display Random Posts in WordPress appeared first on WPBeginner.