How to Uninstall and Reinstall WordPress

Recently, one of our users asked us how they can uninstall and reintsall WordPress? Reinstalling WordPress can solve issues when all other troubleshootings tips fail. In this article, we will show you how to safely uninstall and reinstall WordPress without losing your data or SEO.… Read More »

The post How to Uninstall and Reinstall WordPress appeared first on WPBeginner.

Recently, one of our users asked us how they can uninstall and reintsall WordPress? Reinstalling WordPress can solve issues when all other troubleshootings tips fail. In this article, we will show you how to safely uninstall and reinstall WordPress without losing your data or SEO.

How to uninstall and reinstall WordPress

When Do You Need to Reinstall WordPress?

Reinstalling WordPress should never be the first option. Most common WordPress errors are easily fixable, and this will save you from the hassle of reinstalling WordPress.

If you cannot figure out the cause of an issue, then follow the instructions in our WordPress troubleshooting guide. It will help you pin-point the issue and find a solution.

In case of a hacked WordPress site, you can try the tips in our guide on how to clean a hacked WordPress site.

If all else fails, then uninstalling and reinstalling a fresh copy of WordPress can be used as the last resort.

Step 0. Create an Emergency Backup

Before you do anything, you should first create a complete backup of your existing WordPress site. You can use a WordPress backup plugin to do this. Make sure that you store your backup files on your computer or a cloud storage service like Google Drive or Dropbox.

We will not be using this backup to reinstall WordPress, but it’s good to have in case something goes wrong.

Step 1. Export Your WordPress Content

First thing you need to do is export your WordPress content by creating a WordPress export file. This file will contain all your posts, pages, categories, tags, and comments.

Restoring a WordPress site using this export file allows you to leave out data created by WordPress plugins.

Here is how you would create a WordPress export file.

First, sign in to your WordPress admin area and then go to Tools » Export page. Select all content and then click on ‘Download Export File’ button.

Download WordPress export file

If you have a lot of registered users on your website, then you may want to export them too. See our guide on how to easily import/export users in WordPress.

Step 2. Download wp-content Folder

All your WordPress themes, plugins, images, and uploads are stored in the /wp-content/ folder on your website.

Let’s download this content to your computer, so that you can use it later to reinstall WordPress.

Connect to your WordPress site using an FTP client or File Manager in cPanel. Once connected, select the wp-content folder and download it to your computer.

Download wp-content folder

After downloading the wp-content folder, you are ready to uninstall WordPress.

Step 3. Properly Uninstall WordPress

To uninstall WordPress, you need to connect to your WordPress site using a FTP client or File Manager in cPanel. Then you need to delete all WordPress files.

You don’t really need to delete your WordPress database. Most WordPress hosting companies allow you to create as many databases and usernames as you need.

Instead of deleting the existing database, you can create a new one with a new username and password.

To create new database, you need to login to your cPanel account and click on MySQL Databases icon.

MySQL Databases

This will bring you to the add new database page.

First, you need to enter a name for your new database and click on create database button.

Create a new database

After that, scroll down to add ‘MySQL Users’ section and add a new user. You will need to enter a username and password, and then click on ‘Create User’ button.

Add New MySQL user

Now you need to add the user to the database you created earlier. Scroll down to ‘Add user to database’ section and then select the username and database you created earlier.

Add user to database

Click on the ‘Add’ button to continue.

Your new database is ready to be used when you reinstall WordPress.

Now that you have successfully uninstalled WordPress, let’s see how to reinstall it and restore your website.

Step 4. Fresh Install WordPress

You need to download a fresh copy of WordPress from WordPress.org website.

Download WordPress

After downloading WordPress, you need to unzip the download file.

You will find a WordPress folder inside it. Open the WordPress folder, and you will see all the WordPress files.

Now, you need to upload these files to your website using an FTP client.

Upload WordPress files

After uploading the WordPress files, go ahead and visit your website. WordPress will now ask you to enter your database information.

Add database info

You need to enter the name of database, username, and password you created earlier. Your host information will most likely be localhost.

Once you are done filling out the information, click on the submit button to continue.

WordPress will now attempt to connect to your database. Upon successful connection, it will show you a success message. You can now click on the ‘Run Install’ button to continue.

Run WordPress installation

In the next step, WordPress will ask you to provide your site information like site title, description, admin email address and password.

Site information

After filling out the information, click on ‘Install WordPress’ button to continue.

WordPress will now finish the installation. Go ahead and log into the WordPress admin area using the username and password you entered earlier.

Once you are logged into WordPress, you need to delete the default content.

Head over to Posts and delete the ‘Hello World’ post. Visit the ‘Comments’ section and delete the default comment. Lastly, go to Pages and delete the sample page.

You have successfully reinstalled a fresh copy of WordPress.

Now let’s move on to restoring your content.

Step 5. Restore Uploads, Images, and Theme

First, you will need to restore your uploads, images, and theme located inside the wp-content folder you downloaded earlier.

To do that, you need to connect to your website using an FTP client and go to /wp-content/ folder.

Next, you need to select the /wp-content/uploads/ folder from your computer and upload it to your website.

Upload the uploads folder

If you have made changes to your WordPress theme or child theme files, then you can upload them now. Your theme folders are located in the /wp-content/themes/ folder.

Step 6. Import Content

Now let’s import your posts, pages, categories, tags, and other content.

First, you need to go to Tools » Import page and then click on ‘Install Now’ link under WordPress.

Install WordPress importer

WordPress will now download and install the WordPress importer. After that you need to click on the ‘Run Importer’ link.

This will bring you to WordPress importer page where you need to click on the ‘Choose File’ button and then select the XML file you downloaded during our step 1.

Importing WordPress XML file

Click on ‘Upload file and import’ button to continue.

WordPress will ask you if you want to create new authors and assign the posts to them or if you would like to assign all posts to your current user account.

Import settings

If it is a single author WordPress site, then you can assign all posts to yourself. Otherwise, do nothing and WordPress will import the authors.

You also need to make sure that you check the box under ‘Import Attachments’. This will allow WordPress to properly import the images in your /wp-content/uploads/ folder to the WordPress media library.

Go ahead and click on the Submit button to continue.

WordPress will now start importing content from the XML file to your fresh WordPress install.

Once finished, you will be able to see your content by visiting your website.

Step 7. Install WordPress Plugins (One by One)

After successfully importing content to your reinstalled WordPress site, you can move on to installing plugins.

You will need to install all plugins one by one and then activate them. You may need to manually setup plugins to adjust their settings.

That’s all, you have successfully uninstalled and reinstalled WordPress. You can now review your website and setup things as they were before like your navigation menus, sidebar widgets, contact form, and more.

We hope this article helped you learn how to uninstall and reinstall WordPress. You may also want to see our ultimate step by step WordPress security guide.

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 Uninstall and Reinstall WordPress appeared first on WPBeginner.

How to Create a Custom WordPress Widget

Do you want to create your own custom widgets in WordPress? Widgets allow you to drag and drop elements into any sidebar or widget ready area of your website. In this article, we will show you how to easily create a custom WordPress widget. What… Read More »

The post How to Create a Custom WordPress Widget appeared first on WPBeginner.

Do you want to create your own custom widgets in WordPress? Widgets allow you to drag and drop elements into any sidebar or widget ready area of your website. In this article, we will show you how to easily create a custom WordPress widget.

Creating a custom WordPress widget

What is a WordPress Widget?

WordPress widgets contain pieces of code that you can add to your website’s sidebars or widget ready areas. Think of them as modules that you can use to add different elements by using a simple drag and drop interface.

By default, WordPress comes with a standard set of widgets that you can use with any WordPress theme. See our beginner’s guide on how to add and use widgets in WordPress.

WordPress widgets

WordPress also allows developers to create their own custom widgets. Many WordPress themes and plugins come with their own custom widgets that you can add to your sidebars.

For example, you can add a contact form, a custom login form, or a photo gallery to a sidebar without writing any code.

Having said that, let’s see how to easily create your own custom widgets in WordPress.

Creating a Custom Widget in WordPress

Before we get started, it would be best if you create a site-specific plugin where you will be pasting the widget code from this tutorial.

You can also paste the code in your theme’s functions.php file. However, it will only be available when that particular theme is active.

In this tutorial, we will create a simple widget that just greets visitors. Take a look at this code and then paste it in your site-specific plugin to see it in action.


// Register and load the widget
function wpb_load_widget() {
	register_widget( 'wpb_widget' );
}
add_action( 'widgets_init', 'wpb_load_widget' );

// Creating the widget 
class wpb_widget extends WP_Widget {

function __construct() {
parent::__construct(

// Base ID of your widget
'wpb_widget', 

// Widget name will appear in UI
__('WPBeginner Widget', 'wpb_widget_domain'), 

// Widget description
array( 'description' => __( 'Sample widget based on WPBeginner Tutorial', 'wpb_widget_domain' ), ) 
);
}

// Creating widget front-end

public function widget( $args, $instance ) {
$title = apply_filters( 'widget_title', $instance['title'] );

// before and after widget arguments are defined by themes
echo $args['before_widget'];
if ( ! empty( $title ) )
echo $args['before_title'] . $title . $args['after_title'];

// This is where you run the code and display the output
echo __( 'Hello, World!', 'wpb_widget_domain' );
echo $args['after_widget'];
}
		
// Widget Backend 
public function form( $instance ) {
if ( isset( $instance[ 'title' ] ) ) {
$title = $instance[ 'title' ];
}
else {
$title = __( 'New title', 'wpb_widget_domain' );
}
// Widget admin form
?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> 
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
</p>
<?php 
}
	
// Updating widget replacing old instances with new
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
return $instance;
}
} // Class wpb_widget ends here

After adding the code you need to head over to Appearance » Widgets page. You will notice the new WPBeginner Widget in the list of available widgets. You need to drag and drop this widget to a sidebar.

Custom WordPress widget added to a sidebar

Now you can visit your website to see it in action.

Previewing your custom widget

Now let’s study the code again.

First we registered the ‘wpb_widget’ and loaded our custom widget. After that we defined what that widget does, and how to display the widget back-end.

Lastly, we defined how to handle changes made to the widget.

Now there are a few things that you might want to ask. For example, what’s the purpose wpb_text_domain?

WordPress uses gettext to handle translation and localization. This wpb_text_domain and __e tells gettext to make a string available for translation. See how you can find translation ready WordPress themes.

If you are creating a custom widget for your theme, then you can replace wpb_text_domain with your theme’s text domain.

We hope this article helped you learn how to easily create a custom WordPress widget. You may also want to see our list of the most useful WordPress widgets for your site.

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 Create a Custom WordPress Widget appeared first on WPBeginner.

12 Most Useful .htaccess Tricks for WordPress

Are you looking for some useful .htaccess tricks for your WordPress site. The .htaccess file is a powerful configuration file which allows you to do a lot of neat things on your website. In this article, we will show you some of the most useful… Read More »

The post 12 Most Useful .htaccess Tricks for WordPress appeared first on WPBeginner.

Are you looking for some useful .htaccess tricks for your WordPress site. The .htaccess file is a powerful configuration file which allows you to do a lot of neat things on your website. In this article, we will show you some of the most useful .htaccess tricks for WordPress that you can try right away.

Most Useful .htaccess Tricks for WordPress

What is .htaccess File and How to Edit it?

The .htaccess file is a server configuration file. It allows you to define rules for your server to follow for your website.

WordPress uses .htaccess file to generate SEO friendly URL structure. However, this file can do a lot more.

The .htaccess file is located in your WordPress site’s root folder. You will need to connect to your website using an FTP client to edit it.

.htaccess file on a WordPress site

If you cannot find your .htaccess file, then see our guide on how to find .htaccess file in WordPress.

Before editing your .htaccess file, it is important to download a copy of it to your computer as backup. You can use that file in case anything goes wrong.

Having said that, let’s take a look at some useful .htaccess tricks for WordPress that you can try.

1. Protect Your WordPress Admin Area

You can use .htaccess to protect your WordPress admin area by limiting the access to selected IP addresses only. Simply copy and paste this code into 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.

2. Password Protect WordPress Admin Folder

Password protect WordPress admin directory

If you access your WordPress site from multiple locations including public internet spots, then limiting access to specific IP addresses may not work for you.

You can use .htaccess file to add an additional password protection to your WordPress admin area.

First, you need to generate a .htpasswds file. You can easily create one by using this online generator.

Upload this .htpasswds file outside your publicly accessible web directory or /public_html/ folder. A good path would be:

/home/user/.htpasswds/public_html/wp-admin/passwd/

Next, create a .htaccess file and upload it in /wp-admin/ directory and then add the following codes in there:

AuthName "Admins Only"
AuthUserFile /home/yourdirectory/.htpasswds/public_html/wp-admin/passwd
AuthGroupFile /dev/null
AuthType basic
require user putyourusernamehere
<Files admin-ajax.php>
Order allow,deny
Allow from all
Satisfy any 
</Files>

Important: Don’t forget to replace AuthUserFile path with the file path of your .htpasswds file and add your own username.

For detailed instructions, see our guide on how to password protect WordPress admin folder.

3. Disable Directory Browsing

Disable directory browsing

Many WordPress security experts recommend disabling directory browsing. With directory browsing enabled, hackers can look into your site’s directory and file structure to find a vulnerable file.

To disable directory browsing on your website, you need to add the following line to your .htaccess file.

Options -Indexes

For more on this topic, see our guide on how to disable directory browsing in WordPress.

4. Disable PHP Execution in Some WordPress Directories

Sometimes hackers break into a WordPress site and install a backdoor. These backdoor files are often disguised as core WordPress files and are placed in /wp-includes/ or /wp-content/uploads/ folders.

An easier way to improve your WordPress security is by disabling PHP execution for some WordPress directories.

You will need to create a blank .htaccess file on your computer and then paste the following code inside it.

<Files *.php>
deny from all
</Files>

Save the file and then upload it to your /wp-content/uploads/ and /wp-includes/ directories. For more information check out our tutorial on how to disable PHP execution in certain WordPress directories.

5. Protect Your WordPress Configuration wp-config.php File

Probably the most important file in your WordPress website’s root directory is wp-config.php file. It contains information about your WordPress database and how to connect to it.

To protect your wp-config.php file from unathorized access, simply add this code to your .htaccess file:

<files wp-config.php>
order allow,deny
deny from all
</files>

6. Setting up 301 Redirects Through .htaccess File

Using 301 redirects is the most SEO friendly way to tell your users that a content has moved to a new location. If you want to properly manage your 301 redirects on posts per post basis, then check out our guide on how to setup redirects in WordPress.

On the other hand, if you want to quickly setup redirects, then all you need to do is paste this code in your .htaccess file.

Redirect 301 /oldurl/ http://www.example.com/newurl
Redirect 301 /category/television/ http://www.example.com/category/tv/

7. Ban Suspicious IP Addresses

Are you seeing unusually high requests to your website from a specific IP address? You can easily block those requests by blocking the IP address in your .htaccess file.

Add the following code to your .htaccess file:

<Limit GET POST>
order allow,deny
deny from xxx.xxx.xx.x
allow from all
</Limit>

Don’t forget to replace xx with the IP address you want to block.

8. Disable Image Hotlinking in WordPress Using .htaccess

Other websites directly hotlinking images from your site can make your WordPress site slow and exceed your bandwidth limit. This isn’t a big issue for most smaller websites. However, if you run a popular website or a website with lots of photos, then this could become a serious concern.

You can prevent image hotlinking by adding this code to your .htaccess file:

#disable hotlinking of images with forbidden or custom image option
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?wpbeginner.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?google.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ – [NC,F,L] 

This code only allows images to be displayed if the request is originating from wpbeginner.com or Google.com. Don’t forget to replace wpbeginner.com with your own domain name.

For more ways to protect your images see our guide on ways to prevent image theft in WordPress.

9. Protect .htaccess From Unauthorized Access

As you have seen that there are so many things that can be done using the .htaccess file. Due to the power and control it has on your web server, it is important to protect it from unauthorized access by hackers. Simply add following code to your .htaccess file:

<files ~ "^.*\.([Hh][Tt][Aa])">
order allow,deny
deny from all
satisfy all
</files>

10. Increase File Upload Size in WordPress

There are different ways to increase the file upload size limit in WordPress. However, for users on shared hosting some of these methods do not work.

One of the methods that has worked for many users is by adding following code to their .htaccess file:

php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value max_execution_time 300
php_value max_input_time 300

This code simply tells your web server to use these values to increase file upload size as well as maximum execution time in WordPress.

11. Disable Access to XML-RPC File Using .htaccess

Each WordPress install comes with a file called xmlrpc.php. This file allows third-party apps to connect to your WordPress site. Most WordPress security experts advise that if you are not using any third party apps, then you should disable this feature.

There are multiple ways to do that, one of them is by adding the following code to your .htaccess file:

# Block WordPress xmlrpc.php requests
<Files xmlrpc.php>
order deny,allow
deny from all
</Files>

For more information, see our guide on how to disable XML-RPC in WordPress.

12. Blocking Author Scans in WordPress

A common technique used in brute force attacks is to run author scans on a WordPress site and then attempt to crack passwords for those usernames.

You can block such scans by adding the following code to your .htaccess file:

# BEGIN block author scans
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} (author=\d+) [NC]
RewriteRule .* - [F]
# END block author scans 

For more information, see our article on how to discourage brute force attacks by blocking author scans in WordPress.

We hope this article helped you learn the most useful .htaccess tricks for WordPress. 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 12 Most Useful .htaccess Tricks for WordPress appeared first on WPBeginner.

How to Display Author’s Twitter and Facebook on the Profile Page

Do you want to display your author’s Twitter and Facebook links on their WordPress profile page? By default, WordPress user profile page does not have any fields to add Facebook or Twitter profiles. In this article, we will show you how to easily display author’s… Read More »

The post How to Display Author’s Twitter and Facebook on the Profile Page appeared first on WPBeginner.

Do you want to display your author’s Twitter and Facebook links on their WordPress profile page? By default, WordPress user profile page does not have any fields to add Facebook or Twitter profiles. In this article, we will show you how to easily display author’s Twitter and Facebook profile links in WordPress.

How to Add Author's Twitter & Facebook in WordPress Profile Page

1. Add Twitter and Facebook Profiles with Author Bio Box

This method is easier and is recommended for all users.

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

Upon activation, you need to visit the Settings » Author Bio Box page in your WordPress admin to configure plugin settings.

Author bio box

First you need to select where you want to display the author bio box. The plugin can automatically show the author bio box below posts only or below posts and on homepage.

After that you can select background color, text color, gravatar size, border, etc.

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

Next, you need to go to the Users » All Users page. Here you need to click on the edit link below the user account.

Edit author profile

This will bring you to the user’s profile page. You will notice that there are new social profile fields available on this page.

Now you just need to enter the author’s Facebook, Twitter, or any other social media profile URLs in the respective fields.

Enter your social profile URLs

Once you are done, click on the update profile link.

You can now view any posts written by that user, and you will see their author bio box with icons for their Twitter, Facebook, and other social media profiles.

Author bio box with social profiles

Registered users on your WordPress site can also edit their own profiles to add links for their Facebook and Twitter pages. You can also send an email to all registered users on your website and ask them to update their profiles.

2. Display Twitter and Facebook Profiles with Yoast SEO

This method is for advanced users because it will require you to edit WordPress theme files. If you haven’t done this before, then check out our guide on how to copy and paste code in WordPress.

If you are already using Yoast SEO plugin on your website, then you are in luck as it can be used to add Twitter and Facebook profile fields in author’s profile page.

The problem is that Yoast does not automatically display them in the author bio, but don’t worry we will show you how to do that.

Related: How to properly install and setup Yoast SEO plugin on your website.

Once you have Yoast plugin setup, you need to head over to the Users » All Users page, and then click on the edit link below the author name.

Edit author profile

On the user’s profile page, you will notice new Facebook and Twitter profile fields. For Twitter, you just need to enter the user handle without @ symbol.

For Facebook, you will need to enter the complete Facebook profile URL.

Facebook and Twitter fields in user profile

Once you are done, click on the update profile button to store your changes.

Now you need to display these fields as links in your theme.

You can do this by adding the following code to your theme files where you want to display the author profile links.

<?php 
$twitter = get_the_author_meta( 'twitter', $post->post_author );
$facebook = get_the_author_meta( 'facebook', $post->post_author );
echo '<a href="https://twitter.com/' . $twitter .'" rel="nofollow" target="_blank">Twitter</a> | <a href="'. $facebook .'" rel="nofollow" target="_blank">Facebook</a>';
?> 

Save your changes and view a post on your website.

Here is how it looked on our demo website.

Author social profile links

We hope this article helped you learn how to display author’s Twitter and Facebook profile links in WordPress. You may also want to see our list of how to show an authors list with photos in 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 Author’s Twitter and Facebook on the Profile Page appeared first on WPBeginner.

How to Block IP Addresses in WordPress

Do you want to block specific IP addresses from accessing your WordPress site? Blocking IP addresses is used as a solution to block spam and hacking attacks on your website. In this article, we will show you how to block IP addresses in WordPress, and… Read More »

The post How to Block IP Addresses in WordPress appeared first on WPBeginner.

Do you want to block specific IP addresses from accessing your WordPress site? Blocking IP addresses is used as a solution to block spam and hacking attacks on your website. In this article, we will show you how to block IP addresses in WordPress, and we will also show you how to find out which IP addresses needs to be blocked.

How to Block IP Addresses in WordPress

What is an IP Address?

If internet was a physical world, then think of IP addresses as country, street, and house numbers. They are basically 4 sets of numbers from 0-255 separated by dots and look like this:

172.16.254.1

Each computer connected to the internet has an IP address assigned to them by their internet service provider.

All visitors to your website have an IP address which is stored in your website’s access log files. This means that all websites that you visit also stores your IP address.

You can hide this information by using a VPN service. This allows you to hide your IP address and other personal information.

Why & When You Need to Block IP Addresses?

Blocking an IP address from accessing your website is an effective way to deal with unwanted visitors, comment spam, email spam, hacking attempts, and DDOS (denial of service) attacks.

The most common sign that your website is under a DDOS attack is that your website will frequently become inaccessible or your pages will start taking forever to load.

The other attacks are more obvious such as when you start getting spam comments or a lot of spam emails from your contact form. We have a list of ways to fight spam comments, but the last solution is to block IP addresses.

Finding Out IP Addresses You Want to Block in WordPress

WordPress stores an IP addresses for users that leave a comment on your website. You can see their IP address by visiting the comments page in your WordPress admin area.

IP addresses stored in WordPress comments

If your website is under DDOS attack, then the best way to locate the IP addresses is by checking your server’s access log.

To see those logs, you will need to login to the cPanel dashboard of your WordPress hosting account. Next, locate the ‘logs’ section and click on the ‘Raw Access Logs’ icon.

Raw access logs

This will take you to the access logs page where you need to click on your domain name to download the access logs file.

Download access log file

Your access log file will be inside a .gz archive file. Go ahead and extract the file by clicking on it. If your computer does not have a program to handle .gz archive files, then you will need to install one. Winzip or 7-zip are two popular choices among Windows users.

Inside the archive, you will see your access log file which you can open in a plain text editor like Notepad or TextEdit.

The access log file contains raw data of all requests made to your website. Each line begins with the IP address making that request.

IP addresses in access log file

You need to make sure that you don’t end up blocking yourself, legit users, or search engines from accessing your website. Copy a suspicious looking IP address and use online IP lookup tools to find out more about it.

You will have to carefully look at your access logs for suspicious unusually high number of requests from a particular IP address. Tip: there’s a way to automate this that we share at the bottom of this article.

Once you have located those IP addresses, you need to copy and paste them in a separate text file.

Blocking IP Addresses in WordPress

If you just want to stop users with a specific IP address from leaving a comment on your site, then you can do that inside your WordPress admin area.

Head over to Settings » Discussion page and scroll down to ‘Comment Blacklist’ text box.

Blacklist IP addresses in WordPress comments

Copy and paste the IP addresses that you want to block and then click on the save changes button.

WordPress will now block users with these IP addresses from leaving a comment on your website. These users will still be able to visit your website, but they will see an error message when they try to submit a comment.

Blocking an IP Address Using cPanel

This method completely blocks an IP address from accessing or viewing your website. You should use this method when you want to protect your WordPress site from hacking attempts and DDOS attacks.

First, you need to login to cPanel dashboard of your hosting account. Now scroll down to the security section and click on ‘IP Address Deny Manager’ icon.

IP Address Deny Manager tool in cPanel

This will take you to the IP Address Deny Manager tool. Here you can add the IP addresses you want to block. You can add a single IP address or an IP range and then click on the add button.

Blocking IP addresses in cPanel

You can come back to the same page again if you ever need to unblock those IP addresses.

When IP Address Blocking Doesn’t Work – Automate It!

Blocking an IP address would work if you are just blocking some basic hacking attempts, specific users, or users from specific regions or countries.

However, many hacking attempts and attacks are made using a wide range of random IP addresses from all over the world. It is impossible for you to keep up with all those random IP addresses.

That’s when you need a Web Application Firewall (WAF). For the WPBeginner website, we use Sucuri. It is a website security service that protects your website against such attacks using a website application firewall.

Basically, all your website traffic goes through their servers where it is examined for suspicious activity. It automatically blocks suspicious IP addresses from reaching your website altogether. See how Sucuri helped us block 450,000 WordPress attacks in 3 months.

We hope this article helped you learn how to easily block IP addresses in WordPress. 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 How to Block IP Addresses in WordPress appeared first on WPBeginner.

55+ Most Wanted WordPress Tips, Tricks, and Hacks

Ever wondered what WordPress tips, tricks, and hacks most popular WordPress sites are using? In this article, we will share some of the most wanted WordPress tips, tricks, and hacks that will help you use WordPress like a pro. 1. Use a Custom Homepage By… Read More »

The post 55+ Most Wanted WordPress Tips, Tricks, and Hacks appeared first on WPBeginner.

Ever wondered what WordPress tips, tricks, and hacks most popular WordPress sites are using? In this article, we will share some of the most wanted WordPress tips, tricks, and hacks that will help you use WordPress like a pro.

Most wanted WordPress tips, tricks, and hacks

1. Use a Custom Homepage

By default, WordPress shows your latest posts on the homepage of your website. You can change that and use any page as your site’s homepage.

First you need to create a new page in WordPress, and you can name this page home. Next, you will need to create another page and let’s call this page blog as you will use it to display your blog posts.

Now go to Settings » Reading page in your WordPress admin and under ‘Front page displays’ option and switch to ‘A static page’. After that you will be able to select the pages you just created as your home and blog pages.

Static Front Page

You can also create a custom homepage template to use for your home page. Simply create a new file on your computer using a plain text editor and add this code at the top of it.

<?php /* Template Name: Custom Homepage */ ?>

Save this file as custom-homepage.php on your desktop.

Next, you need to connect to your website using an FTP client and go to /wp-content/themes/your-current-theme/ folder. Now upload the file you created earlier to your theme folder.

Return back to the WordPress admin area and edit your home page. You will be able to select your custom homepage template under the page attributes metabox.

Custom home page template

For more details see our guide on how to create a custom page template in WordPress.

Now this page will be completely empty and it will not show anything at all. You can use custom HTML/CSS and WordPress template tags to build your own page layout. You can also use a page builder plugin to easily create one using drag and drop tools.

2. Install Google Analytics in WordPress

Google Analytics is one of the must have tools for WordPress site owners. It allows you to see where your users are coming from and what they are doing on your website.

The best way to install Google Analytics is by using the MonsterInsights plugin. You can insert Google Analytics code into your theme files, but this code will disappear when you update or switch your theme.

For detailed instructions see our step by step guide on how to install Google Analytics in WordPress.

3. Password Protect WordPress Admin Directory

WordPress admin directory is where you perform all administrative tasks on your website. It is already password protected as users are required to enter username and password before they can access the admin area.

However by adding another layer of authentication, you can make it difficult for hackers to gain access to your WordPress site.

Here is how to enable password protection for your WordPress admin directory.

Login to cPanel dashboard of your WordPress hosting account. Under the security section, you need to click on ‘Password Protect Directories’ icon.

Password protect directories

Next, you will be asked to select the directories you want to protect. Select /wp-admin/ folder and next create a username and password.

Security settings

That is it. Now when you try to access your wp-admin directory, you should see an authentication required box like this:

Password protected directory

For alternate method and more detailed instructions see our guide on how to password protect your WordPress admin directory.

4. Show Images in Rows and Columns

Display photos in rows and columns

By default, when you add multiple images to a WordPress post, they would appear right next to each other or on top of each other. This does not look very good because your users will have to scroll a lot to see all of them.

This can be solved by displaying thumbnail images in a grid layout. This gives your website a more compact look and improves user experience.

For complete step by step instructions, see our guide on how to display WordPress photos in rows and columns.

5. Allow users to Subscribe to Comments

Comment subscription checkbox

Normally when users leave a comment on your website, they will have to manually visit the same article again to see if you or other users replied to comments.

Wouldn’t it be better if users were able to get email notifications about new comments on your posts? Here is how to add this feature to your website.

Simply install and activate the Subscribe to Comments Reloaded plugin. Upon activation, you need to visit Settings » Subscribe to Comments to configure the plugin settings.

For detailed instructions see our guide on how to allow users to subscribe to comments in WordPress.

6. Limit login attempts

Locked out login

By default, a WordPress user can make unlimited number of attempts to login to a WordPress site. This allows anyone to try guessing your password until they get it right.

To control this, you need to install and activate the Login LockDown plugin. It allows you to set limits on the number of failed attempts a user can make to login.

For detailed setup instructions see our guide on how to limit login attempts in WordPress.

7. Display Excerpt (Post Summary) on Home and Archive Pages

Post excerpts

You may have noticed that all popular blogs show article summary instead of full article on their home and archive pages. It makes those pages load faster, increases page views, and avoids duplicate content across your website.

For more on this topic, see our article on excerpt (summary) vs full posts in WordPress archive pages.

Many premium and free WordPress themes already use excerpts on home and archive pages. However, if your theme doesn’t display excerpts, then see our guide on how to display post excerpts in WordPress themes.

8. Add Custom Default Gravatar Image

WordPress uses Gravatar to display user profile photos in WordPress. If a user does not have a gravatar, then WordPress uses a default image which is called ‘Mystery Person’.

This default gravatar image will appear many times in your WordPress comments area simply because a lot of users do not have a gravatar image associated with their email address.

You can easily replace this default gravatar with your own custom default gravatar image.

First you will need to upload the image you want to use as your default gravatar image to your WordPress media library.

Next, you need to copy the image file URL.

Copy file URL

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

add_filter( 'avatar_defaults', 'wpb_new_gravatar' );
function wpb_new_gravatar ($avatar_defaults) {
$myavatar = 'http://example.com/wp-content/uploads/2017/01/wpb-default-gravatar.png';
$avatar_defaults[$myavatar] = "Default Gravatar";
return $avatar_defaults;
}

Don’t forget to replace $myavatar value with the URL of the custom gravatar image you uploaded earlier.

You can now visit Settings » Discussion page, and you will notice your custom default avatar added to default avatar choices.

For detailed instructions check out our tutorial on how to add change the default gravatar in WordPress.

9. Adding custom CSS to a WordPress Theme

As a WordPress site owner, sometimes you may need to add custom CSS to your site. CSS allows you to change the appearance of things on your WordPress site like colors, margins, font sizes, etc.

The easiest way to add custom CSS to any WordPress theme is by visiting the Appearance » Customize page in your WordPress admin. This will launch the WordPress theme customizer, and you will see your website’s preview in the right panel.

Now click on the ‘Additional CSS’ menu in the left panel to expand it.

Additional CSS in theme customizer

You will see a plain text box where you can add your custom CSS. As soon as you add a valid CSS rule, you will be able to see it applied on your website’s live preview pane.

Custom CSS code and preview

Don’t forget to click on the ‘Save & Publish’ button on the top when you are finished.

For alternate methods and more detailed instructions check out our beginner’s guide on how to add custom CSS in WordPress.

10. Using Inspect Element Tool to Customize WordPress

Adding custom CSS sounds great, but how do you know which CSS classes to edit? How do you debug it without actually having to write CSS?

Using Inspect Element tool, you can edit HTML, CSS, or JavaScript code for any webpage and see your changes live (only on your computer).

For a DIY website owner, these tools can help you preview how a site design would look without actually making the changes for everyone.

Simply point and right click on any element on a page, then select ‘Inspect’ from your browser’s menu.

Opening Inspect Element or developer tools in your browser

This will split your browser window, and you will be able to see the HTML and CSS source code of the page.

HTML and CSS panels in Inspect tool

Any changes you make here will be immediately visible on the page above. However, keep in mind that these changes are only happening in your browser and you are not actually editing the page.

This allows you to figure out what you need to edit and how. After that you can go ahead and change your actual theme files or custom CSS code.

For more on this topic, see our article on basics of Inspect element and customizing WordPress as DIY user.

11. Add a Facebook Thumbnail Image

Facebook can automatically pick up an image from your articles when they are shared by you or anyone else. Usually it picks the featured image of an article. However, sometimes it may pick a random image from the article that may not be suitable.

If you are using Yoast SEO plugin, then you can select a Facebook thumbnail image in Yoast SEO metabox on the post edit screen.

Selecting a Facebook thumbnail image for an article in Yoast SEO

You can also select a Facebook thumbnail image for your homepage by visiting SEO » Social page.

Setting a Facebook thumbnail for home page

If you are not using Yoast SEO plugin, then see our guide on how to fix Facebook incorrect thumbnail issue in WordPress.

12. Add Featured Image or Post Thumbnail to RSS Feed

WordPress RSS feeds shows a list of your most recent articles. If you are showing full articles in the feed, then all images inside will be displayed. However, it does not include the featured image or post thumbnail in the article.

To fix this, you can add the following code to your theme’s functions.php file or a site-specific plugin.

function rss_post_thumbnail($content) {
global $post;
if(has_post_thumbnail($post->ID)) {
$content = '<p>' . get_the_post_thumbnail($post->ID) .
'</p>' . get_the_content();
}
return $content;
}
add_filter('the_excerpt_rss', 'rss_post_thumbnail');
add_filter('the_content_feed', 'rss_post_thumbnail');

For more information, see our tutorial on how to add post thumbnail to RSS feeds in WordPress.

13. Show Excerpts in RSS Feed

By default, WordPress shows your full article in the RSS feed. This allows content scrapers to automatically fetch and steal your full articles. It also prevents your RSS feed subscribers from visiting your website.

To fix this, head over to Settings » Reading page and scroll down to ‘For each article in a feed, show’ option. Select summary and then click on the save changes button.

14. Use Shortcodes inside Text Widgets

Shortcodes allow you to easily add small functions into WordPress posts and pages. However, they do not work in the text widget.

To run shortcodes in your sidebar text widgets, you need to add this code to your theme’s functions.php file or a site-specific plugin.

add_filter('widget_text', 'do_shortcode');

You can also use the Shortcode Widget plugin, which adds a shortcode enabled text widget to your WordPress site.

For more information, take a look at our guide on how to add shortcodes in WordPress sidebar widgets.

15. Add Images in WordPress Sidebar

WordPress does not come with an easy way to just upload and display images in your sidebar (though it is expected to change soon in an upcoming version). At the moment if you want to add an image, then you need to add the HTML code for it.

First, you need to upload the image to your WordPress site using the media uploader and copy its URL.

Next, go to Appearance » Widgets page and add a text widget to your sidebar. Inside the text widget you will need to add the HTML in the following format.

<img src="Paste image URL here" alt="Alternate text" />

You can now save your widget settings and preview your website.

For more details see our guide on how to add an image in WordPress sidebar widget.

16. Add Content to Articles in RSS Feeds

Want to manipulate your WordPress RSS feeds by adding content to your articles visible only for your RSS feed subscribers?

Add the following code to your theme’s functions.php file or a site-specific plugin.

function wpbeginner_postrss($content) {
if(is_feed()){
$content = 'This post was written by Syed Balkhi '.$content.'Check out WPBeginner';
}
return $content;
}
add_filter('the_excerpt_rss', 'wpbeginner_postrss');
add_filter('the_content', 'wpbeginner_postrss');

This code shows the text ‘This post was written by Syed Balkhi’ before an article and ‘Check out WPBeginner’ after the article.

For more ways to manipulate RSS feed content, see our guide on how to add content in your WordPress RSS feeds.

17. Delay Posts in RSS Feeds

Have you ever published an article accidentally before it was ready to go live? We have all been there. You can easily just unpublish the article and continue editing it.

However, RSS feed readers and email subscribers may already get it in their inbox. There is an easy fix to avoid this -delaying posts from appearing in your RSS feed.

Add the following code to your theme’s functions.php file or a site-specific plugin.

function publish_later_on_feed($where) {

	global $wpdb;

	if ( is_feed() ) {
		// timestamp in WP-format
		$now = gmdate('Y-m-d H:i:s');

		// value for wait; + device
		$wait = '10'; // integer

		// http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_timestampdiff
		$device = 'MINUTE'; //MINUTE, HOUR, DAY, WEEK, MONTH, YEAR

		// add SQL-sytax to default $where
		$where .= " AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, '$now') > $wait ";
	}
	return $where;
}

add_filter('posts_where', 'publish_later_on_feed');

This code delays your published posts from appearing in RSS feed for 10 minutes.

For more details see our article on how to delay posts from appearing in WordPress RSS feed.

18. Display Random Header Images in WordPress

Want to display random header images on your WordPress site? Most WordPress themes come with built-in support to display header image across your website. However, you can also upload multiple header images and allow your theme to randomly display a header image.

Head over to Appearance » Customize page and then click on the ‘Header’ Section to expand it. Now upload all the header images that you want to use and then click on the ‘Randomize header images’ button.

Randomize header images in WordPress

If you want to display select few images on different articles and pages, then check out our guide on how to add random header images to your WordPress site.

19. Add Image Icons to Links Navigation Menu

Adding menu icons

Do you want to display image icons next to links in your navigation menu? The easiest solution is to use the Menu Image plugin.

After installing the plugin, simply head over to Appearance » Menu, and you will see the option to add images with each item in your existing menu.

If for some reason, you don’t want to use a plugin and would rather do it manually, then follow the steps below:

First you need to visit Appearance » Menus page and then click on the Screen Options button at the top right corner of the screen.

Enable CSS classes option for Navigation Menus

This will bring down a menu where you need to check the box next to CSS classes option.

After that scroll down to your navigation menu and click on an item to expand it. You will see an option to add CSS classes. Enter a different CSS class for each menu item.

Adding a CSS class to a menu item in WordPress

Don’t forget to click on the save menu button to store your changes.

Next, you need to upload the image icons to your WordPress site by visiting Media » Add Media page. After uploading the image files copy their URLs as you will need them in the next step.

Now you can add an image icon to your navigation menu by adding custom CSS. Here is a sample CSS that you can use as an starting point.

.homepage {
background-image: url('http://www.example.com/wp-content/uploads/2014/12/home.png');
background-repeat: no-repeat;
background-position: left;
padding-left: 5px;
}

Don’t forget to replace image URL with your own image file URL.

20. Open Navigation Menu Link in New Window

Sometimes you may need to make a navigation menu link open in a new window. The problem is you do not see an option to do that when adding menu items.

Actually, the option is hidden to remove clutter from the screen. You will need to click on the screen options button at the top right corner of the screen and check the ‘link target’ option.

Link target option in navigation menu screen

Next, you need to scroll down to the menu item that you want to open in a new window. Click on the menu item to expand it, and you will see the option to open link in a new tab.

Open link in a new tab or window

Don’t forget to click on the save menu button to store your changes.

21. Add Full Screen Search Overlay in WordPress

Full screen search overlay on a WordPress site

If you click on the search icon at the top right corner of any page on WPBeginner, then you will notice a full screen search overlay appear. It improves search experience and makes it more engaging.

You can add this to your WordPress site as well. The easiest way to do this is by installing and activating the WordPress Full Screen Search Overlay plugin.

The plugin works out of the box and there are no settings for you to configure. Upon activation, it turns any default WordPress search form field into a full screen search overlay.

For more details, see our guide on how to add a full screen search overlay in WordPress.

22. Add a Sticky Floating Navigation Menu

A sticky floating navigation menu stays on top of the screen as a user scrolls down. Some WordPress themes have this feature as an option in their settings. If your theme doesn’t have this option, then you can try this method.

First, you need to install and activate the Sticky Menu (or Anything!) on Scroll plugin.

Upon activation, go to plugin’s settings page located under Settings » Sticky Menu (or Anything!). Add the CSS class of your navigation menu and save changes.

For detailed instructions, see our tutorial on how to create a sticky floating navigation menu in WordPress.

23. Add multiple authors to a WordPress post

Do you want to credit multiple authors for an article on your website? By default, WordPress posts are assigned to a single author. However, if you often need to credit multiple authors, then there is an easier way to to do this.

You will need to install and activate the Co-Authors Plus plugin.

Now go ahead and edit the post or page where you want to credit multiple authors. On the post edit screen, you will notice the new ‘Authors’ box just below the post editor where you can credit multiple authors.

Select multiple authors

24. Add Categories to WordPress Pages

Want to add categories and tags to pages in WordPress? By default, they are only available for posts. Mainly, because pages are supposed to be static standalone content (see difference between posts and pages in WordPress).

If you want to add categories and tags, then simply add this code to your theme’s functions.php file or a site-specific plugin.

// add tag and category support to pages
function tags_categories_support_all() {
  register_taxonomy_for_object_type('post_tag', 'page');
  register_taxonomy_for_object_type('category', 'page');  
}

// ensure all tags and categories are included in queries
function tags_categories_support_query($wp_query) {
  if ($wp_query->get('tag')) $wp_query->set('post_type', 'any');
  if ($wp_query->get('category_name')) $wp_query->set('post_type', 'any');
}

// tag and category hooks
add_action('init', 'tags_categories_support_all');
add_action('pre_get_posts', 'tags_categories_support_query');

25. Create a Local WordPress Site on Your Computer

Many WordPress site owners and developers install WordPress on their computer. It allows you to develop a WordPress site locally, try plugins and themes, and learn WordPress basics.

We created detailed step by step instructions on how to install WordPress on your Windows computer or on Mac using MAMP.

26. Display Total Number of Comments in WordPress

Comments provide an easier way for users to engage with content on your website. Showing total number of comments can be used as social proof and encourage more users to participate in discussions.

The easiest way to do this is by installing the Simple Blog Stats plugin. Upon activation, you can add [sbs_apoproved] shortcode to any post or page to display total number of comments.

For a code method and more instructions see our article on how to display total number of comments in WordPress.

27. Show Total Number of Registered Users in WordPress

User count preview in WordPress

If you allow users to register on your WordPress site, then showing total number of registered users can encourage more users to signup.

The easiest way to do this is by installing the Simple Blog Stats plugin. Upon activation, you can add [sbs_users] shortcode to any post or page to display total number of registered users.

For more detailed instructions, see our tutorial on how to show total number of registered users in WordPress.

28. Create New Image Sizes in WordPress

When you upload an image to your blog, WordPress automatically creates several copies of the image. Your WordPress theme and plugins can also add new image sizes.

To create new image sizes in WordPress, you need to add the following code to your theme’s functions.php file or a site-specific plugin.

add_image_size( 'sidebar-thumb', 120, 120, true ); // Hard Crop Mode
add_image_size( 'homepage-thumb', 220, 180 ); // Soft Crop Mode
add_image_size( 'singlepost-thumb', 590, 9999 ); // Unlimited Height Mode

This code adds three new image sizes. Don’t forget to change image size names and dimensions to your own requirements.

For more information, see our tutorial on how to create new image sizes in WordPress.

29. Add Category Icons in WordPress

Want to add category icons or images next to category names in WordPress? It makes your category archive pages look more engaging and improves user experience.

First you need to install and activate the Taxonomy Images plugin in WordPress. Upon activation, head over to Posts » Categories and click on the add button next to blank thumbnail icon for each category.

Add category images in WordPress

For detailed instructions, see our guide on how to add taxonomy images (category icons) in WordPress.

30. Convert Categories to Tags or Vice versa

Often folks are not clear about how to properly use categories and tags in WordPress. Sometimes you may end up creating categories which should have been tags or vice versa.

It is easily fixable.

Head over to Tools » Import page and then install Categories and Tags Converter.

Install categories and tags converter in WordPress

After installation, click on the run importer link to continue.

On the converter page, you can switch between categories to tags or tags to categories converter. Next, select the items you want to convert and then click on the convert button.

Convert button

31. Bulk Move Posts Between Categories and Tags

Sometimes you may want to bulk move posts between categories and tags. Doing that one by one for each post can be time consuming.

Actually, there is a plugin for that. Simply install and activate the Bulk Move plugin. Upon activation, you need to go to Tools » Bulk Move to move your posts.

Moving posts between categories and categories

For more detailed instructions, visit our tutorial on how to bulk move posts to categories and tags in WordPress.

32. Display Last Updated Date of Your Posts

Last updated date for posts in WordPress

By default, most WordPress themes will show the date when an article was published. This is fine, and would work for most websites and blogs.

However, if you regularly update your old content, then you may want to show your users when an article was last updated. Otherwise you users wouldn’t notice that the article contains current information.

This can be achieved by adding the following code to

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 = get_the_modified_time('F jS, Y');
$updated_time = get_the_modified_time('h:i a'); 
$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' );

For more detailed instructions see our guide on how to display last updated date in WordPress.

33. How to Display Relative Dates in WordPress

Want to display relative dates like yesterday, 10 hours ago, or a week ago for your posts in WordPress? Relative dates give users a sense of how much time has passed since something was posted.

To add relative dates, you need to install and activate the Meks Time Ago plugin. Upon activation, you need to visit Settings » General page and scroll down to ‘Meks Time Ago Options’ section.

Meks Time Ago plugin settings

You can select when to use time ago and how to display it. Don’t forget to click on the save changes button to store your settings.

For more details, see our guide on how to display relative dates in WordPress.

34. Remove WordPress Version Number

By default WordPress adds the WordPress version in your website’s header. Some people think it’s a security liability to which our answer is to keep WordPress updated.

However if you want to remove the WordPress version number, simply add the following code to your theme’s functions.php file or a site-specific plugin.

function wpbeginner_remove_version() {
return '';
}
add_filter('the_generator', 'wpbeginner_remove_version');

For more information on this topic see our article on the right way to remove WordPress version number.

35. Update WordPress URLs when Not Able to Access WP-Admin

WordPress Site Address

Sometimes when moving a WordPress site to new domain or due to a misconfiguration you may need to update WordPress URLs.

These URLs tell WordPress where to display your site and where WordPress core files are located. Incorrect settings can lock you out of WordPress admin area or redirect you to the old website.

The easiest way to update WordPress URLs is by adding this code to your current theme’s functions.php file.

update_option( 'siteurl', 'http://example.com' );
update_option( 'home', 'http://example.com' );

Don’t forget to replace example.com with your own domain name. Once you access your WordPress site go to Settings » General page and update the URLs there. After that you need to remove the code you added to the functions file.

If you also need to update URLs in your posts and pages, then see our guide on how to properly update URLs when moving your WordPress site.

36. Deactivate All Plugins when not able to access WP-admin

When troubleshooting WordPress errors, you will be often asked to deactivate all WordPress plugins. You can just go to Plugins page and deactivate all plugins. But what if you are locked out of your WordPress site?

Here is how you can easily deactivate plugins when locked out of admin area.

First connect to your WordPress site using an FTP client and go to /wp-content/ folder. Inside it, you will find the plugins folder.

Renaming plugins folder to deactivate all WordPress plugins

Now you just need to rename the plugins folder to plugins.old and WordPress will automatically deactivate all plugins.

For alternate method and more information see our guide on how to deactivate all plugins when not able to access wp-admin.

37. Remove Default Image Links in WordPress

By default, when you upload images using the media uploader, WordPress asks you select how you would like to link to an image. If you don’t want to link to an image, then you can select None.

A better way to deal with this is by adding the following code to your theme’s functions.php file or a site-specific plugin.

function wpb_imagelink_setup() {
	$image_set = get_option( 'image_default_link_type' );
	
	if ($image_set !== 'none') {
		update_option('image_default_link_type', 'none');
	}
}
add_action('admin_init', 'wpb_imagelink_setup', 10);

This code automatically sets default image linking option to none.

For more on this topic check out our guide on how to automatically remove default image link in WordPress.

38. Include Category in Post URLs

You may have noticed that many WordPress sites use category in their post URLs. This allows them to add more useful information into a URL which is good for user experience as well as SEO.

If you want to add category name into your WordPress post URLs, then head over to Settings » Permalinks page. Click on the custom structure and add /%category%/%postname%/ in the field next to it.

Adding category to WordPress post URLs

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

To learn more on how WordPress will handle subcategories and multiple categories, see our guide on how to include category and subcategories in WordPress URLs.

39. Display Random Posts in WordPress

Want to display random posts in your WordPress sidebar? Random posts give your users a chance to discover articles that they would otherwise never get to see.

First, you need to install and activate the Advanced Random Posts Widget plugin. Upon activation, head over to Appearance » Widgets page and then add Random Posts widget to a sidebar.

For an alternate code method, see our guide on how to display random posts in WordPress.

40. Allow user registration on your WordPress Site

WordPress comes with a powerful user management system with different roles and capabilities. If you want to allow users to register on your site, here is how you would turn on that feature.

Head over to Settings » General page and click on the check box next to ‘membership’ option. Below that you need to choose the default role that will be assigned to new users, if you are unsure, then use subscriber.

For more details see our guide on how to allow user registration on your WordPress site.

41. Create a Custom User Registration Form in WordPress

When you open user registration on your site, users will be using the default WordPress registration form. You can replace it with a custom user registration form for an improved user experience.

First you will need to install and activate the WPForms plugin. You will need at least the Pro plan to get access to their user registration addon.

Upon activation, go to WPForms » Addons page to install and activate the user registration addon.

After that you need to create a new form by visiting WPForms » Add New page. This will launch the WPForms builder where you need to select the User Registration Form as your template.

After creating your form you need to click on the embed button to copy the embed code. Now you can add this code to any WordPress post or page to display your custom user registration form.

For more detailed instructions see our guide on how to create a custom user registration form in WordPress.

42. Exclude Specific Categories from RSS Feed

Sometimes you may need to exclude specific categories from your WordPress RSS feed. The easiest way to do that is by installing and activating the Ultimate Category Excluder plugin.

Upon activation, head over to Settings » Category Exclusion page to configure plugin settings.

Category excluder

Select the categories you want to exclude and then click on the save changes button to store your settings.

43. Change Excerpt Length in WordPress

The default WordPress excerpt length is often too short to describe a post’s summary. To change excerpt length you can add the following code to your theme’s functions.php file or a site-specific plugin.

// Changing excerpt length
function new_excerpt_length($length) {
return 100;
}
add_filter('excerpt_length', 'new_excerpt_length');

// Changing excerpt more
function new_excerpt_more($more) {
return '...';
}
add_filter('excerpt_more', 'new_excerpt_more');

If you do not want to mess with code, then see our guide on how to customize WordPress excerpts (no coding required).

44. Display Dynamic Copyright Date in WordPress

To add a copyright date to your WordPress site’s footer, you can just edit the footer template in your theme and add a copyright notice. However, the year you use in the code will need to be manually updated next year.

Instead, you can use the following code to dynamically display the current year in your copyright notice.

&copy; 2009 – <?php echo date('Y'); ?> YourSite.com

For more advance solution, check out our article on how to add dynamic copyright date in WordPress.

45. How to Change a User Name in WordPress

WordPress allows you to easily change the name of a user, but you cannot change the username. There are two ways of doing this.

The easiest way is by using a plugin called Username Changer. After activating the plugin, go to Users » Username Changer page in your WordPress admin.

Changing a username in WordPress with Username Changer plugin

Select the username you want to change, and then enter the new username.

For alternate methods, see our article on how to change your WordPress username.

46. Allow Users to Like or Dislike Comments

WordPress comment with like dislike buttons

Have you seen how many popular sites like YouTube allow users to like and dislike comments. This brings more user engagement to the discussion on your website.

First you need to install and activate the Comments Like Dislike plugin.

Upon activation, you need to visit Comments » Comments Like Dislike page to configure plugin settings.

Like Dislike Comments

For more details, see our guide on how to allow users to like or dislike comments in WordPress.

47. Duplicate a WordPress Post or Page

The manual way to do duplicate a post is by creating a new post or page and then copying the content from the old one. However, this wouldn’t copy the post settings like categories, featured image, tags, etc.

The more efficient way to do this is by using the Duplicate Post plugin. Simply install and activate the plugin and then go to Posts » All Posts page.

Cone or draft a WordPress post

You will see the option to clone a post or create a new draft.

For more detailed instructions, see our article on how to easily duplicate posts and pages in WordPress with a single click.

48. Allow Users to Submit Posts to Your WordPress Site

Authors on your WordPress site can just login to their account and write posts. But what if you wanted your users to be able to submit posts directly without creating an account?

The best way to do this by creating a blog post submission form.

You will need to install and activate the WPForms plugin. You will need the pro version of the plugin to access the post submission addon.

Upon activation, go to WPForms » Addons page to download and activate the post submissions addon.

After that you can go to WPForms » Add New page and then select ‘Blog post submission form’ as your template.

Blog post submission form

Once you are done editing the form click on the embed button to copy the form embed code. Now you can paste this code in any WordPress post or page to display a blog post submission form.

Posts submitted by users will be stored in your WordPress posts as pending review. You can then review, edit and publish them.

For more detailed instructions, take a look at our guide on how to allow users to submit posts to your WordPress site.

49. Turn Off Comment Notification Emails in WordPress

WordPress automatically sends email notifications when someone leaves a comment or when a comment is awaiting moderation. This is exciting when you first start your blog, but it becomes very annoying after a short while.

The good news is that you can easily turn these notifications off. Visit the Settings » Discussion page on your WordPress admin and then scroll down to ‘Email Me Whenever’ section. Uncheck both options and then click on the save changes button.

Turn off comment notification emails

50. Change Sender Name in Outgoing WordPress Emails

By default, when WordPress sends an email notification it uses ‘WordPress’ as the sender name. This looks a bit unprofessional and you may want to change it to a real person or your website title.

You can easily change that by adding this code to your theme’s functions file or a site-specific plugin.

// Function to change email address

function wpb_sender_email( $original_email_address ) {
    return [email protected]';
}

// Function to change sender name
function wpb_sender_name( $original_email_from ) {
	return 'Tim Smith';
}

// Hooking up our functions to WordPress filters 
add_filter( 'wp_mail_from', 'wpb_sender_email' );
add_filter( 'wp_mail_from_name', 'wpb_sender_name' );

If you would rather do it using a plugin, then see our guide on how to change sender name in outgoing WordPress emails.

51. Changing the Author of a WordPress Post

Want to change the author of a WordPress post? By default, the option to change post author is hidden on the post edit screen.

You will need to edit the post where you want to change the author name and then click on Screen Options button at the top right corner of the screen. Check the box next to author option.

Enable author box

This will display the author meta box on the post edit screen where you can select a different author for the post.

For more details, check out our article on how to change the author of a post in WordPress.

52. Rearrange Post Edit Screen in WordPress

Sometimes you may feel that categories are located too far down on the post edit screen, or featured image box should be higher.

Many users don’t notice it for a while but all the boxes on the post edit screen are quite flexible. You can click to collapse them and even drag and drop them to arrange the post edit screen.

Rearrange post edit screen in WordPress

To learn more, see our tutorial on how to rearrange post edit screen in WordPress.

53. Change Number of Posts Shown on Blog Pages

By default, WordPress shows 10 posts on your blog pages and archives. You can change that to any number you want.

You will need to visit Settings » Reading page and then scroll down to ‘Blog pages show at most’ option. Enter the number of posts you want to display and then click on the save changes button.

Change number of posts

54. Automatically Close Comments on Old Articles

Sometimes you would notice that some very old posts on your site start getting regular spam comments for no apparent reason. One way to deal with this is by closing comments on older articles.

WordPress allows you to automatically turn off comments on old articles. You need to visit Settings » Discussion page and then scroll down to ‘Other comment settings’ section.

Disable comments on old posts

To learn how to deal with spam comments, see these tips to combat comment spam in WordPress.

55. Split Long Posts into Pages

Want to split lengthy posts into pages so that users can easily navigate them without scrolling too much? WordPress makes it super easy, just add the follow code where you want to split a post into next page.

<!––nextpage––>

WordPress will add page break at this point and rest of the post will appear on the next page. You can add the same code again when you want to start another page, and so on.

For more detailed instructions see our guide on how to split WordPress posts into multiple pages.

That’s all for now.

We hope this article helped you find some new WordPress tips, tricks, and hacks. You may also want to see our ultimate guide 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 55+ Most Wanted WordPress Tips, Tricks, and Hacks appeared first on WPBeginner.

How to Fix Render-Blocking JavaScript and CSS in WordPress

Do you want to eliminate render-blocking JavaScript and CSS in WordPress? If you test your website on Google PageSpeed insights, then you will likely see a suggestion to eliminate render-blocking scrips and CSS. In this article, we will show you how to easily fix render… Read More »

The post How to Fix Render-Blocking JavaScript and CSS in WordPress appeared first on WPBeginner.

Do you want to eliminate render-blocking JavaScript and CSS in WordPress? If you test your website on Google PageSpeed insights, then you will likely see a suggestion to eliminate render-blocking scrips and CSS. In this article, we will show you how to easily fix render blocking JavaScript and CSS in WordPress to improve your Google PageSpeed score.

How to fix render blocking JavaScript and CSS in WordPress

What is Render-Blocking JavaScript and CSS?

Every WordPress site has a theme and plugins that add JavaScript and CSS files to the front-end of your website. These scripts can increase your site’s page load time, and they can also block rendering of the page.

A user’s browser will have to load those scripts and CSS before loading rest of the HTML on the page. This means that users on a slower connection will have to wait a few milliseconds more to see the page.

These scripts and stylesheets are referred to as render-blocking JavaScript and CSS.

Website owners who are trying to achieve the Google PageSpeed score of 100 will need to fix this issue to attain that perfect score.

What is Google PageSpeed Score?

Google PageSpeed Insights is an online tool created by Google to help website owners optimize and test their websites. This tool tests your website against Google’s guidelines for speed and offers suggestions to improve your site’s page load time.

It shows you a score based on the number of rules that your site passes. Most websites get somewhere between 50-70. However, some website owners feel compelled to achieve 100 (the highest a page can score).

Do You Really Need the Perfect “100” Google PageSpeed Score?

The purpose of Google PageSpeed insights is to provide you guidelines to improve speed and performance of your website. You are not required to follow these rules strictly.

Remember that speed is only one of the many SEO metrics that help Google determine how to rank your website. The reason speed is so important is because it improves user experience on your site.

A better user experience requires a lot more than just speed. You also need to offer useful information, better user interface, and engaging content with text, images, and videos.

Your goal should be to create a fast website that offers great user experience.

We recently redesigned WPBeginner, and we kept our focus on speed as well as improving user experience.

We recommend that you use Google Pagespeed rules as suggestions, and if you can implement them easily without ruining user experience, then that’s great. Otherwise, you should strive to do as much as you can and then don’t worry about the rest.

Having said that, let’s take a look at what you can do to fix render blocking JavaScript and CSS in WordPress.

We will cover two methods that will fix the render blocking JavaScript and CSS in WordPress. You can choose the one that works best for your website.

1. Fix Render Blocking Scripts and CSS with Autoptimize

This method is simpler and recommended for most users.

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

Upon activation, you need to visit the Settings » Autoptimize page to configure the plugin settings.

Autoptimize Settings

You can start by checking the box next to JavaScript Options and CSS Options and then click on the save changes button.

You can now test your website using PageSpeed tool. If there are still render blocking scripts, then you need to come back to the plugin’s settings page and click on ‘Show Advanced Settings’ button at the top.

Advanced JavaScript Options

Here you can allow plugin to include inline JS and remove scripts that are excluded by default like seal.js or jquery.js.

Next, scroll down to CSS option and allow plugin to aggregate inline CSS.

Click on the ‘Save changes and Empty Cache’ button to save your changes and empty plugin cache.

Once you are done, go ahead and check your website again with the PageSpeed tool.

Make sure that you thoroughly test your website to see that nothing is broken by optimizing your JavaScripts or CSS.

How does it work?

Autoptimize aggregates all enqueued JavaScript and CSS. After that, it creates minified CSS and JavaScripts files and serves cached copies to your website as async or deferred.

This allows you to fix the render blocking scripts and styles issue. However, please keep in mind that it can also affect the performance or appearance of your website.

2. Fix Render Blocking JavaScript using W3 Total Cache

This method requires a little more work and is recommended for users already using W3 Total Cache plugin on their website.

First you will need to install and activate the W3 Total Cache plugin. If you need help, then see our guide on how to install and setup W3 Total Cache for Beginners.

Next, you need to visit Performance » General Settings page and scroll down to Minify section.

W3 Total Cache enable minify

First you need to check ‘Enable’ next to Minify option and then select ‘Manual’ for minify mode option.

Click on the save all settings button to store your settings.

Next, you need to add the scripts and CSS that you want to minify.

You can get the URLs of all the scripts and stylesheets that are render blocking from Google PageSpeed Insights tool.

Under the suggestions where it says: ‘Eliminate render-blocking JavaScript and CSS in above-the-fold content’, click on ‘Show how to fix’. It will show you the list of scripts and stylesheets.

Get JavaScript and Stylesheet URLs from Google PageSpeed tool

Take your mouse over to a script and it will show you the full URL. You can select this URL and then use your keyboard’s CTRL+C (Command+C on Mac) keys to copy the URL.

Now head over to your WordPress admin area and go to Performance » Minify page.

First you need to add JavaScript files that you want to be minified. Scroll down to JS section and then under the ‘Operations in areas’ set the embed type to ‘Non-blocking async’ for the <head> section.

Add scripts to minify

Next, you need to click on the ‘Add script’ button and then start adding script URLs that you copied from Google PageSpeed tool.

Once you are done, scroll down to CSS section and then click on the ‘Add a stylesheet’ button. Now start adding stylesheet URLs you copied from Google PageSpeed tool.

Add stylesheets to minify

Now click on the ‘Save settings and purge cache’ button to store your settings.

Visit the Google PageSpeed tool and test your website again.

Make sure that you also test your website thoroughly to see that everything is working fine.

Troubleshooting

Depending on how the plugins and your WordPress themes uses JavaScript and CSS, it could be quite challenging to completely fix all render blocking JavaScript and CSS issues.

While the above tools can help, your plugins may need certain scripts at a different priority level to work properly. In that case, the above solutions can break your plugins or they could behave unexpectedly.

Google may still show you certain issues like optimizing CSS delivery for above the fold content. Autoptimize allows you to fix that by manually adding inline CSS required to display the above fold area of your theme.

However, it could be quite difficult to find out what CSS code you will need to display above the fold content.

That’s all, we hope this article helped you learn how to fix render blocking JavaScript and CSS in WordPress. You may also want to see our ultimate guide boost WordPress speed and performance 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 How to Fix Render-Blocking JavaScript and CSS in WordPress appeared first on WPBeginner.

How WordPress Plugins Affect Your Site’s Load Time

Have you ever wondered how WordPress plugins affect your site’s load time? WordPress plugins allow you to add features to your site, but they can also affect your website speed. In this article, we will show you how WordPress plugins affect your site’s load time,… Read More »

The post How WordPress Plugins Affect Your Site’s Load Time appeared first on WPBeginner.

Have you ever wondered how WordPress plugins affect your site’s load time? WordPress plugins allow you to add features to your site, but they can also affect your website speed. In this article, we will show you how WordPress plugins affect your site’s load time, and how you can control them more efficiently.

How WordPress plugins affect your site's load time

How WordPress Plugins Work?

WordPress plugins are like apps for your WordPress site. You can install them to add more features to your website like contact forms, photo galleries, or an ecommerce store.

When someone visits your website, WordPress first loads its core files and then loads all your active plugins.

For more details, take a look at our article about what are WordPress plugins? And how do they work?.

How Can Plugins Affect Site Load Time?

Each WordPress plugin offers different functionality and features. To do that, some plugins make database calls on the backend while others load assets on the front-end such as CSS stylesheets, JavaScript files, images, etc.

Making database queries and loading assets adds up to your site’s load time. Most plugins make an HTTP request to load assets like scripts, CSS, and images. Each request increases your site’s page load time.

When done properly, the performance impact is often not too noticeable.

However, if you are using multiple plugins that are making too many http requests to load files and assets, then it will affect your site’s performance and user experience.

How to Check Files Loaded by WordPress Plugins?

To see how plugins are affecting your page load time, you need to check the files loaded by WordPress plugins.

There are plenty of tools that you can use to figure this out.

You can use your browser’s developer tools (Inspect in Google Chrome and Inspect Element in Firefox).

Simply visit your website and right click to select Inspect. This will open the developer tools panel.

You need to click on the ‘Network’ tab and then reload your website. As the page reloads, you will be able to see how your browser loads each file.

See page load time and files loaded with inspect tool

You can also use third-party tools like Pingdom and GTmetrix to see this. Among other useful information, these tools will also show you all files that are loaded and how much time they took to load.

Testing page load time using Pingdom

How Many Plugins are Too Many?

As you see these files being loaded, you may start wondering how many plugins you should I use on my site? How many plugins are too many?

The answer really depends on the set of plugins you are using on your website.

A single bad plugin can load 12 files while multiple good plugins will add just a couple of extra files.

All well-coded plugins try to keep the files they load to a minimum. However, not all plugin developers are that careful. Some plugins will load files on every single page load, even when they don’t need those files.

If you are using too many of such plugins, then this will start affecting your site’s performance.

How to Keep Plugins in Control?

The most important thing you can do on your WordPress site is to only use plugins that are well coded, have good reviews, and are recommended by trusted sources.

See our guide on how to find which WordPress plugins.

If you find that a WordPress plugin is affecting your site’s load, then look for a better plugin that does the same job but better.

Next, you need to start using caching and CDN to further improve your site’s performance and speed.

Another factor you should consider is your website hosting. If your hosting servers are not properly optimized, then it will increase your site’s response time.

This means that not just plugins, but your site’s overall performance will be slower. Make sure you are using one of the best WordPress hosting companies.

As a last resort, you can uninstall plugins that you can live without. Carefully review the installed plugins on your website,and see if you can uninstall some of them. This is not an ideal solution as you will have to compromise on features for speed.

Optimize WordPress Plugin Assets Manually

Advanced WordPress users can try to manage how WordPress plugins load files on their site. Doing so requires some knowledge of coding and some debugging skills.

The proper way to load scripts and stylesheets in WordPress is by using the wp_enqueue_style and wp_enqueue_script functions.

Most WordPress plugin developers use them to load plugin files. WordPress also comes with easy functions to deregister those scripts and stylesheets.

However, if you just disable loading those scripts and stylesheets, then this will break your plugins, and they will not work correctly. To fix that, you will need to copy and paste those styles and scripts into your theme’s stylesheet and JavaScript files.

This way you will be able to load all of them at once, minimizing the http requests and effectively decreasing your page load time.

Let’s see how to easily deregister stylesheets and JavaScript files in WordPress.

Disable Plugin Stylesheets in WordPress

First, you will need to find the name or handle of the stylesheet that you want to deregister. You can locate it using your browser’s inspect tool.

Finding a style name

After finding the stylesheet handle, you can deregister it by adding this code to your theme’s functions.php file or a site-specific plugin.

add_action( 'wp_print_styles', 'my_deregister_styles', 100 );
function my_deregister_styles() {
wp_deregister_style( 'gdwpm_styles-css' );
}

You can deregister as many style handles as you want within this function. For example, if you have more than one plugin to deregister the stylesheet for, then you would do it like this:


add_action( 'wp_print_styles', 'my_deregister_styles', 100 );
function my_deregister_styles() {
wp_deregister_style( 'gdwpm_styles-css' );
wp_deregister_style( 'bfa-font-awesome-css' );
wp_deregister_style( 'some-other-stylesheet-handle' );
}

Remember, that deregistering these stylesheets will affect plugin features on your website. You need to copy the contents of each stylesheet you deregister and paste them in your WordPress theme’s stylesheet or add them as custom CSS.

Disable Plugin JavaScripts in WordPress

Just like stylesheets, you will need to find out the handle used by the JavaScript file to deregister them. However, you will not find the handle using the inspect tool.

For that you will need to dig deeper into plugin files to find out the handle used by the plugin to load a script.

Another way to find out all the handles used by plugins is to add this code into your theme’s functions.php file.

function wpb_display_pluginhandles() { 
$wp_scripts = wp_scripts(); 
$handlename .= "<ul>"; 
    foreach( $wp_scripts->queue as $handle ) :
      $handlename .=  '<li>' . $handle .'</li>';
    endforeach;
$handlename .= "</ul>";
return $handlename; 
}
add_shortcode( 'pluginhandles', 'wpb_display_pluginhandles'); 

After adding this code, you can use [pluginhandles] shortcode to display a list of plugin script handles.

Display a list of plugin script handles in WordPress

Now that you have script handles, you can easily deregister them using the code below:

add_action( 'wp_print_scripts', 'my_deregister_javascript', 100 );

function my_deregister_javascript() {
wp_deregister_script( 'contact-form-7' );
}

You can also use this code to disable multiple scripts, like this:

add_action( 'wp_print_scripts', 'my_deregister_javascript', 100 );

function my_deregister_javascript() {
wp_deregister_script( 'contact-form-7' );
wp_deregister_script( 'gdwpm_lightbox-script' );
wp_deregister_script( 'another-plugin-script' );
}

Now, as we mentioned earlier that disabling these scripts will stop your plugins to work properly.

To avoid this, you will need to combine JavaScripts together, but sometimes it does not work smoothly, so you must know what you are doing. You can learn from trial and error (like a lot of us do), but we recommend you do not do that on a live site.

The best place to test is on a local WordPress install or on a staging site with managed WordPress hosting providers.

Load Scripts Only on Specific Pages

If you know that you will be needing a plugin script to load on a specific page on your website, then you can allow a plugin on that particular page.

This way the script remains disabled on all other pages of your site and is loaded only when needed.

Here is how you can load scripts on specific pages.

add_action( 'wp_print_scripts', 'my_deregister_javascript', 100 );

function my_deregister_javascript() {
if ( !is_page('Contact') ) {
wp_deregister_script( 'contact-form-7' );
}
}

This code simply disables contact-form-7 script on all pages except the contact page.

That’s all for now.

We hope this article helped you learn how WordPress plugins affect your site’s load time. You may also want to see our ultimate guide to improve WordPress speed and site 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 WordPress Plugins Affect Your Site’s Load Time appeared first on WPBeginner.

How WordPress Plugins Affect Your Site’s Load Time

Have you ever wondered how WordPress plugins affect your site’s load time? WordPress plugins allow you to add features to your site, but they can also affect your website speed. In this article, we will show you how WordPress plugins affect your site’s load time,… Read More »

The post How WordPress Plugins Affect Your Site’s Load Time appeared first on WPBeginner.

Have you ever wondered how WordPress plugins affect your site’s load time? WordPress plugins allow you to add features to your site, but they can also affect your website speed. In this article, we will show you how WordPress plugins affect your site’s load time, and how you can control them more efficiently.

How WordPress plugins affect your site's load time

How WordPress Plugins Work?

WordPress plugins are like apps for your WordPress site. You can install them to add more features to your website like contact forms, photo galleries, or an ecommerce store.

When someone visits your website, WordPress first loads its core files and then loads all your active plugins.

For more details, take a look at our article about what are WordPress plugins? And how do they work?.

How Can Plugins Affect Site Load Time?

Each WordPress plugin offers different functionality and features. To do that, some plugins make database calls on the backend while others load assets on the front-end such as CSS stylesheets, JavaScript files, images, etc.

Making database queries and loading assets adds up to your site’s load time. Most plugins make an HTTP request to load assets like scripts, CSS, and images. Each request increases your site’s page load time.

When done properly, the performance impact is often not too noticeable.

However, if you are using multiple plugins that are making too many http requests to load files and assets, then it will affect your site’s performance and user experience.

How to Check Files Loaded by WordPress Plugins?

To see how plugins are affecting your page load time, you need to check the files loaded by WordPress plugins.

There are plenty of tools that you can use to figure this out.

You can use your browser’s developer tools (Inspect in Google Chrome and Inspect Element in Firefox).

Simply visit your website and right click to select Inspect. This will open the developer tools panel.

You need to click on the ‘Network’ tab and then reload your website. As the page reloads, you will be able to see how your browser loads each file.

See page load time and files loaded with inspect tool

You can also use third-party tools like Pingdom and GTmetrix to see this. Among other useful information, these tools will also show you all files that are loaded and how much time they took to load.

Testing page load time using Pingdom

How Many Plugins are Too Many?

As you see these files being loaded, you may start wondering how many plugins you should I use on my site? How many plugins are too many?

The answer really depends on the set of plugins you are using on your website.

A single bad plugin can load 12 files while multiple good plugins will add just a couple of extra files.

All well-coded plugins try to keep the files they load to a minimum. However, not all plugin developers are that careful. Some plugins will load files on every single page load, even when they don’t need those files.

If you are using too many of such plugins, then this will start affecting your site’s performance.

How to Keep Plugins in Control?

The most important thing you can do on your WordPress site is to only use plugins that are well coded, have good reviews, and are recommended by trusted sources.

See our guide on how to find which WordPress plugins.

If you find that a WordPress plugin is affecting your site’s load, then look for a better plugin that does the same job but better.

Next, you need to start using caching and CDN to further improve your site’s performance and speed.

Another factor you should consider is your website hosting. If your hosting servers are not properly optimized, then it will increase your site’s response time.

This means that not just plugins, but your site’s overall performance will be slower. Make sure you are using one of the best WordPress hosting companies.

As a last resort, you can uninstall plugins that you can live without. Carefully review the installed plugins on your website,and see if you can uninstall some of them. This is not an ideal solution as you will have to compromise on features for speed.

Optimize WordPress Plugin Assets Manually

Advanced WordPress users can try to manage how WordPress plugins load files on their site. Doing so requires some knowledge of coding and some debugging skills.

The proper way to load scripts and stylesheets in WordPress is by using the wp_enqueue_style and wp_enqueue_script functions.

Most WordPress plugin developers use them to load plugin files. WordPress also comes with easy functions to deregister those scripts and stylesheets.

However, if you just disable loading those scripts and stylesheets, then this will break your plugins, and they will not work correctly. To fix that, you will need to copy and paste those styles and scripts into your theme’s stylesheet and JavaScript files.

This way you will be able to load all of them at once, minimizing the http requests and effectively decreasing your page load time.

Let’s see how to easily deregister stylesheets and JavaScript files in WordPress.

Disable Plugin Stylesheets in WordPress

First, you will need to find the name or handle of the stylesheet that you want to deregister. You can locate it using your browser’s inspect tool.

Finding a style name

After finding the stylesheet handle, you can deregister it by adding this code to your theme’s functions.php file or a site-specific plugin.

add_action( 'wp_print_styles', 'my_deregister_styles', 100 );
function my_deregister_styles() {
wp_deregister_style( 'gdwpm_styles-css' );
}

You can deregister as many style handles as you want within this function. For example, if you have more than one plugin to deregister the stylesheet for, then you would do it like this:


add_action( 'wp_print_styles', 'my_deregister_styles', 100 );
function my_deregister_styles() {
wp_deregister_style( 'gdwpm_styles-css' );
wp_deregister_style( 'bfa-font-awesome-css' );
wp_deregister_style( 'some-other-stylesheet-handle' );
}

Remember, that deregistering these stylesheets will affect plugin features on your website. You need to copy the contents of each stylesheet you deregister and paste them in your WordPress theme’s stylesheet or add them as custom CSS.

Disable Plugin JavaScripts in WordPress

Just like stylesheets, you will need to find out the handle used by the JavaScript file to deregister them. However, you will not find the handle using the inspect tool.

For that you will need to dig deeper into plugin files to find out the handle used by the plugin to load a script.

Another way to find out all the handles used by plugins is to add this code into your theme’s functions.php file.

function wpb_display_pluginhandles() { 
$wp_scripts = wp_scripts(); 
$handlename .= "<ul>"; 
    foreach( $wp_scripts->queue as $handle ) :
      $handlename .=  '<li>' . $handle .'</li>';
    endforeach;
$handlename .= "</ul>";
return $handlename; 
}
add_shortcode( 'pluginhandles', 'wpb_display_pluginhandles'); 

After adding this code, you can use [pluginhandles] shortcode to display a list of plugin script handles.

Display a list of plugin script handles in WordPress

Now that you have script handles, you can easily deregister them using the code below:

add_action( 'wp_print_scripts', 'my_deregister_javascript', 100 );

function my_deregister_javascript() {
wp_deregister_script( 'contact-form-7' );
}

You can also use this code to disable multiple scripts, like this:

add_action( 'wp_print_scripts', 'my_deregister_javascript', 100 );

function my_deregister_javascript() {
wp_deregister_script( 'contact-form-7' );
wp_deregister_script( 'gdwpm_lightbox-script' );
wp_deregister_script( 'another-plugin-script' );
}

Now, as we mentioned earlier that disabling these scripts will stop your plugins to work properly.

To avoid this, you will need to combine JavaScripts together, but sometimes it does not work smoothly, so you must know what you are doing. You can learn from trial and error (like a lot of us do), but we recommend you do not do that on a live site.

The best place to test is on a local WordPress install or on a staging site with managed WordPress hosting providers.

Load Scripts Only on Specific Pages

If you know that you will be needing a plugin script to load on a specific page on your website, then you can allow a plugin on that particular page.

This way the script remains disabled on all other pages of your site and is loaded only when needed.

Here is how you can load scripts on specific pages.

add_action( 'wp_print_scripts', 'my_deregister_javascript', 100 );

function my_deregister_javascript() {
if ( !is_page('Contact') ) {
wp_deregister_script( 'contact-form-7' );
}
}

This code simply disables contact-form-7 script on all pages except the contact page.

That’s all for now.

We hope this article helped you learn how WordPress plugins affect your site’s load time. You may also want to see our ultimate guide to improve WordPress speed and site 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 WordPress Plugins Affect Your Site’s Load Time appeared first on WPBeginner.

How to Fix “Missing a Temporary Folder” Error in WordPress

Are you seeing ‘Missing a temporary folder’ error on your WordPress site? This error makes it impossible to upload images, update themes and plugins, or update WordPress core. In this article, we will show you how to easily fix “Missing a temporary folder” error in… Read More »

The post How to Fix “Missing a Temporary Folder” Error in WordPress appeared first on WPBeginner.

Are you seeing ‘Missing a temporary folder’ error on your WordPress site? This error makes it impossible to upload images, update themes and plugins, or update WordPress core. In this article, we will show you how to easily fix “Missing a temporary folder” error in WordPress.

How to fix 'Missing temporary folder' error in WordPress

What Causes The ‘Missing a Temporary Folder’ Error in WordPress?

This error is caused by incorrect PHP settings on your WordPress hosting environment. There is a specific PHP setting that defines a temporary folder to be used by apps like WordPress to temporarily store data before saving it to the desired location.

WordPress needs access to this temporary folder when you upload an image, install or update a theme or plugin, or update WordPress core.

If the location of this folder is not defined in your server’s PHP configuration, then WordPress will be unable to do any of these things and will show you ‘Missing a temporary folder’ error.

Missing temporary folder error

Having said that, let’s see how to easily fix the ‘Missing a temporary folder’ error in WordPress.

Fix Missing Temporary Folder Error in WordPress

For this tutorial, you will need to edit wp-config.php file in WordPress. If you haven’t done this before, then please see our guide on how to edit wp-config.php file in WordPress.

First, you will need to connect to your website using an FTP client or File Manager in cPanel dashboard of your hosting account.

Next, you will need to locate the wp-config.php file and edit it.

Editing wp-config.php file using an FTP client

You need to paste this code to the file just before the line that says ‘That’s all, stop editing! Happy blogging’.

define('WP_TEMP_DIR', dirname(__FILE__) . '/wp-content/temp/');

Save your changes and upload the wp-config.php file back to your website.

Next, you need to go to /wp-content/ folder and create a new folder inside it. You need to name this new folder temp.

Creating temp folder

That’s all, you can now visit your WordPress admin area and try uploading an image.

Troubleshooting

If this method doesn’t work, then check the directory permissions for your wp-content folder.

Note: This error is caused by poorly configured hosting environment. The solution described above is just a workaround. You should still ask your hosting provider to fix this. If they don’t, then you should switch to one of these top WordPress hosting companies.

We hope this article helped you fix the ‘Missing a temporary folder’ error in WordPress. You may also want to bookmark our ultimate list of the most common WordPress errors and how to fix them.

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 Fix “Missing a Temporary Folder” Error in WordPress appeared first on WPBeginner.