How To Remove Category From Your WordPress URLs

Categories are a very important feature of any WordPress website. They are very helpful to maintain or browse a website. They tell you what’s related to what and they give your visitors a good way to browse your site. But sometimes they are not serving your URL structures. Then what should you do?

Don’t worry guys we have are here to help. Today we are going to show how to fix this. Meanwhile you may also interested in 20 Reasons Why You Should Use WordPress For Your Website

So, there are different ways to achieve the same and we are going discuss them one by one.  Just remember that if you have a fresh WordPress installation then set up permalinks as you want. But if you are changing permalinks structure on a live website, do properly, redirect old URLs to new ones to avoid loses.

Remove Category from WordPress URLs with a Dot

  1. Go to Settings -> Permalinks.
  2. Select Custom Structure and put /%category%/%postname%/ there.
  3. Assign a dot to the Category base field and save the change.

The below picture will help you to understand.

Please remember that providing dot to Category base in settings is a must. As leaving it blank will use the default value. Visit a post after saving settings and check the URL, it won’t have the category base now. While this trick currently works, there’s no assurance that it will work in the future as well.

Remove Category From Your URLs with .htaccess

RewriteRule ^category/(.+)$$1 [R=301,L]

You can also add this code to your .htaccess file through FTP rather than using a dot. Add the code before the closing </IfModule> tag in the file and it will remove the category slug from WordPress permalink.

What if I am using Yoast SEO Plugin

The current version of SEO by Yoast plugin has discontinued the option of category removal from URLs. The last version had the option in the Advanced menu of plugin settings. The websites, who are using Yoast for a long time, still have their URLs without the category base.

If you’ve installed Yoast plugin on your fresh WordPress website, check the post URLs as well. While we’re not sure, the feature might be still there and working silently. Else there are other plugins as well to remove category slug.

Removing Category from Slug using a Plugin.

The plugin ‘Remove Category URL’ is much popular and has additional advantages too. You can try the plugin if your website is older than 6 months. It will redirect the old category permalinks to the new ones, which is better for SEO. Also, you don’t need to configure anything or modify a file. Get the WordPress official plugin URL here.

Although you can always write a function for the functionality it makes the site slower. At last, all easy methods to remove the category slug from URLs are there. Do let us know in the comment section which one do you prefer.


How to know That Your WordPress Site is Hacked

1.Sudden Drop in Website Traffic

If you look at your Google Analytics reports and see a sudden drop in traffic, then this could be a sign that your WordPress site is hacked.

There are many malware and trojans out there that hijack your website’s traffic and redirect it to spammy websites. Some of them don’t redirect logged in users which allows them to go unnoticed for a while.

Another reason for the sudden drop in traffic is Google’s safe browsing tool, which might be showing warnings to users regarding your website.
Each week, Google blacklists around 20,000 websites for malware and around 50,000 for phishing. That’s why every blogger and business owner needs to pay serious attention to their WordPress security.

You can check your website using the Google’s safe browsing tool to see your safety report.

2. Bad Links Added to Your Website

One of the most common signs among hacked WordPress sites is data injection. Hackers create a backdoor on your WordPress site which gives them access to modify your WordPress files and database.

Some of these hacks add links to spammy websites. Usually these links are added to the footer of your website, but they really could be any where. Deleting the links will not guarantee that they will not come back.

You will need to find and fix the backdoor used to inject this data into your website. See our guide on how to find and fix a backdoor in a hacked WordPress site.

3. Your Site’s Homepage is Defaced

This is probably the most obvious one as it is clearly visible on the homepage of your website. Most hacking attempts do not deface your site’s home page because they want to remain unnoticed for as long as possible.

However, some hackers may deface your website to announce that it has been hacked. Such hackers usually replace your homepage with their own message. Some hackers may even try to extort money from site owners.

4. You are Unable to Login to WordPress

If you are unable to login to your WordPress site, then there is a chance that hackers may have deleted your admin account from WordPress.

Since the account doesn’t exist, you would not be able to reset your password from the login page. There are other ways to add an admin account using phpMyAdmin or via FTP. However, your site will remain unsafe until you figure out how a hacker got into your website.

5. Suspicious User Accounts in WordPress

If your site is open to user registration, and you are not using any spam registration protection, then spam user accounts are just common spam that you can simply delete.

However, if you don’t remember allowing user registration and notice new user accounts in WordPress, then your site is probably hacked.

Usually the suspicious account will have administrator user role, and in some cases you may not be able to delete it from your WordPress admin area.

6. Unknown Files and Scripts on Your Server

If you’re using a site scanner plugin like Sucuri, then it will alert you when it finds an unknown file or script on your server.

You need to connect to your WordPress site using a FTP client. The most common place where you will find malicious files and scripts is the /wp-content/ folder.

Usually, these files are named like WordPress files to hide in plain sight. Deleting these files immediately will not guarantee that these files will not return. You will need to audit the security of your website specially file and directory structure.

7. Your Website is Often Slow or Unresponsive

All websites on internet can become victims of random denial of service attacks. These attacks use several hacked computers and servers from all over the world using fake ips. Sometimes they are just sending too many requests to your server, other times they are actively trying to break into your website.

Any such activity will make your website slow, unresponsive, and unavailable. You will need to check your server logs to see which ips are making too many requests and block them.

It is also possible that your WordPress site is just slow and not hacked. In that case, you need to follow our guide to boost WordPress speed and performance.

8. Unusual Activity in Server Logs

Server logs are plain text files stored on your web server. These files keep record of all errors occurring on your server as well as all your internet traffic.

You can access them from your WordPress hosting account’s cPanel dashboard under statistics.

These server logs can help you understand what’s going on when your WordPress site is under attack. They also contain all the ip addresses used to access your website which allows you to block suspicious ip addresses.

9. Failure to Send or Receive WordPress Emails

Hacked servers are commonly used for spam. Most WordPress hostingcompanies offer free email accounts with your hosting. Many WordPress site owners use their host’s mail servers to send WordPress emails.

If you are unable to send or recieve WordPress emails, then there is a chance that your mail server is hacked to send spam emails.

10. Suspicious Scheduled Tasks

Web servers allow users to set up cron jobs. These are scheduled tasks that you can add to your server. WordPress itself uses cron to setup scheduled tasks like publishing scheduled posts, deleting old comments from trash, and so on.

A hacker can exploit cron to run scheduled tasks on your server without you knowing it.

11. Hijacked Search Results

If the search results from your website show incorrect title or meta description, then this is a sign that your WordPress site is hacked.

Looking at your WordPress site, you will still see the correct title and description. The hacker has again exploited a backdoor to inject malicious code which modifies your site data in a way that it is visible only to search engines.

12. Popups or Pop Under Ads on Your Website

These types of hacks are trying to make money by hijacking your website’s traffic and showing them their own spam ads for illegal websites. These popups do not appear for logged in visitors or visitors accessing a website directly.

They only appear to the users visiting from search engines. Pop under ads open in new window and remain unnoticeable by users.

15 Common WordPress Errors With Solutions

We all love WordPress, but sometimes it can drive us crazy! Whether its the dreaded white screen of death, an unknown PHP error coming from a plugin or server issues causing our site to crash, it’s never fun. But whenever WordPress decides to act up, don’t worry yourself at all – there is always a solution as you’re going to learn in this post. Get ready to have fun because you and me are going to solve 15 common WordPress errors. So without further ado, let’s start with the most common WordPress error.

1. Internal Server Error

Almost every WordPress user I know has encountered the internal server error at least once. It’s quite annoying because, unlike many common WordPress errors, the internal server error does not tell you what you need to fix. This can be frustrating since the error can be a result of several reasons as you’ll see below.

Internal Server Error Causes:

Some of the possible causes for the Internal Server error are the following:

  • Corrupted plugin functions
  • Corrupted theme functions
  • Corrupted .htaccess
  • Exhausted PHP memory limit

Internal Server Error Solutions:

This error can easily send a beginner into panic mode but worry not, here are some solutions.

a. Edit .htaccess file
Since the internal server error is mainly a result of a corrupted .htaccess file, login into your WordPress root directory via File Manager (or FTP) and rename your .htaccess file to .htaccess.old. Refresh your browser to see if you solved the error. If the error disappeared, go to Settings -> Permalinks and click on the Save Changes button to reset your .htacess and flush write rules. If this does not work, perhaps you need to check your plugins.

b. Deactivate all plugins
A plugin you just installed could be the problem, but that’s great because you know what to uninstall or delete. Other times, this WordPress error may crop up as a result of an old plugin (or several plugins that are incompatible). You won’t know for sure if the problem is your plugins unless you deactivate the plugins.

c. Change Themes
If the problem was not the plugins, perhaps your theme is. Switch to the Twenty Twelve theme and reload your website. If you’re still seeing the error, perhaps you need to upgrade some of your WordPress folders.

d. Repair the wp-admin and wp-includes folders
By this point, you’ve probably solved this WordPress error. But if this is not the case, try replacing your wp-admin and wp-includes folders with newer ones from a fresh WordPress install.

e. Increase your PHP memory Limit
If everything else fails, you have to get down and dirty and mess with a few things on your server. The internal server error can be frustrating, so I don’t expect anything to stop you. Here is a great guide on increasing PHP memory by the good guys at WordPress.If you like taking shortcuts, fire up your code editor and create a text file named php.ini. Inside this file, add this code:


Save and upload the file to the /wp-admin/ folder. If increasing your PHP memory solves the problem, talk to your web host to put a finger on what is exhausting your memory. It could be anything from broken theme functions to poorly designed plugins among other things. Your web host will furnish you with information from your server logs.

2. Auto-Update Failed

WordPress now comes with an auto-update feature that takes care of security, minor bugs and such like things. The feature is pure genius at work. It’s great but sometimes it fails. Considering the auto-update feature does not require any human input, how do you tell when the update fails? You will see one of the following:

  • A PHP error message
  • A blank white screen (Also known as the white screen of death – WSOD)
  • A warning that says the update failed

Update Failed Causes:

  • Internet connection problems during auto-update
  • Broken connection with main WordPress files
  • Incorrect file permissions

Update Failed Solution:

Update your WordPress website manually. If you don’t know where to start, please check out this Updating WordPress – Manual Update post at WordPress Codex.

3. Syntax WordPress Error

My analysis showed that this is a very common WordPress error among people who add code snippets to their WordPress sites. When you encounter this error, you will usually notice something like:

Parse error - syntax error, unexpected $end in /public_html/your_site/wp-content/themes/your-theme/functions.php on line 38

This error needn’t stress you out for it tells you exactly where to find the problem.

Syntax Error Cause:

Many a time, the syntax error is caused by some missing or unexpected character(s) in the problematic file. Most of the time caused by someone less experienced trying to edit the code in a theme or plugin but it could also occur when you’ve installed a new theme or plugin that contains the error.

Syntax Error Solutions:

a. Educate yourself on pasting code snippets into WordPress
As a WordPress beginner, you have a long (but fun) way to go as far as learning WordPress development is concerned. There is no hurry though, so take your time. If you encountered this WordPress error after adding code snippets into your WordPress website, you need to learn more about pasting code snippets into WordPress or you will cause more damage.

b. Fix the affected code
If this WordPress error occurred after updating a plugin or pasting some code from the web, you know exactly where to look. The problem is you can’t fix your code via Appearance -> Editor (or Plugins -> Editor) since the syntax error locks you out of your website.This doesn’t auger well with most beginners, so they freak out. But don’t be, you can easily edit your WordPress files via FTP or File Manager in your cPanel. Find the affected file and fix the code either by removing it or rewriting it correctly.

c. Try a different theme or plugin
If the error began when you activated a new theme or plugin then it’s most likely an error in that theme or plugin. So you might want to find an alternative one or contact the developer so they can fix the error. In some cases you might not be able to log into WordPress in which case you might have to delete the plugin or theme via FTP.

4. Error Establishing A Database Connection

Of the common WordPress errors, this is pretty self-explanatory. The error lets you know something broke the connection to your WordPress database.

Database Establishing Error Causes:

  • wp-config.php error
  • Problems with your hosting provider
  • You’ve been hacked! And here I was thinking this particular WordPress error is no big deal.

Database Establishing Error Solutions:

a. Edit your wp-config.php file
Access your wp-config.php file via File Manager or FTP and confirm if the database name, host, username and password are correct. If you’re stuck or don’t know what to do first, consider teaching yourself a few things about editing wp-config.php files.

b. Fix issues with your web host
If your wp-config.php is looking right and this WordPress error is still a problem, you should talk to your WordPress hosting provider. They will be able to tell you whether the server is down or your database was shut down for exceeding its quota. If they tell you everything looks good on their end, it is time to implement some WordPress security on your site.

c. Scan your website to determine if it’s compromised
Hackers don’t sleep. No, they don’t. You can fall victim to a hacker anytime, especially if you don’t know how to secure your WordPress website. To ensure your website hasn’t been hacked, scan it using a tool such as Sucuri Sitecheck. If you get bad news, just stay calm and check out this my site was hacked post over at WordPress Codex.

5. Briefly Unavailable For Scheduled Maintenance Error

1, 2, 3… Break time over, let’s try and understand why you’re getting this not-so-brief WordPress error. Oh, by the way, it shouldn’t trouble you at all since it’s quite easy to solve. But first, let’s look at the causes.

Scheduled Maintenance Error Causes:

  • Your WordPress update failed because some things are beyond your control
  • The .maintenance file was not deleted after the update for one reason or another

Scheduled Maintenance Error Solutions:

Are you having fun? Do you feel you can solve the above errors if/when they crop up? If you can, let’s move on to WordPress error number six (6).

6. Email Password Retrieval Does Not Work

The main cause for this is forgetfulness. Perhaps you should try some memory enhancing diet and exercises ? Kidding aside…we all forget even the most important of things such as passwords, usernames and email addresses? As it were, you forgot your password and were forced to use the “Lost Your Password” page. The problem is you never received the reset link via email. You decide to try again after checking your spam folder but still, no link.

Password Retrieval Error Cause:

For some reason your WordPress installation just won’t send you the link…the cause could be a mystery! But the main problem isn’t why you aren’t receiving your password but how can you actually reset your password easily and quickly? We’ll, below are a couple solutions.

Password Retrieval Error Solutions:

a. Reset your WordPress via phpMyAdmin
This is the more technical of the two solutions I’ll present you with.

  1. Login into your cPanel and navigate to phpMyAdmin under Databases
  2. Select your database (Your web host will help you can’t find your database)
  3. Navigate to wp_users and click on Browse
  4. Go to your username and click on Edit
  5. Enter a new value (your new password) into user_pass
  6. Choose MD5 from the drop-down menu that’s under Function
  7. Click Go button at the bottom to save your changes

b. Edit your functions.php file
And now for a slightly less technical method. The functions.php file is responsible for many a thing on your WordPress website. If your email password retrieval is giving you a hard time:

  1. Navigate to “../wp-content/themes/your_live_theme/” using FTP or File Manager and download the functions.php file.
  2. Open the file in your code editor and add the following code:
    wp_set_password('DesiredNewPassword', 1);

    Replace DesiredNewPassword with your new passowrd. Number one (1) in the code is your user ID number in the wp_users table.

  3. Save and upload functions.php
  4. When you can login into your website, eliminate the code (download functions.php, delete code and upload it back to your theme folder)

7. HTTP Error 403 – Forbidden

If you get “You are not authorized to view this page. (403 error)” message when trying to login into your WordPress website, you’ve encountered one of the most common WordPress errors – the HTTP Error 403.

HTTP 403 Error Cause:

  • Problems with Directory Indexes if your blog is hosted on a Windows server

HTTP 403 Error Solution:

Add index.php to the Directory Indexes. You can solve this WordPress error easily by adding index.php to the Directory Indexes. Just go to your Control Panel -> Web Options -> Directory Indexes and add index.php.

8. Sidebar Below Content Error

I was quite perplexed when I first encountered this WordPress error. I was so convinced my theme was completely toast that I contemplated changing it altogether. However, I summoned Google spiders and a few seconds later, I realized this was just one of the most common WordPress errors. This realization took away all the worrying. A few more clicks and scrolls, I found the causes.

Sidebar Below Content Error Causes:

  • HTML errors – sometimes you might forget to close a few div elements
  • CSS errors – Other times, you might accidentally use disproportionate widths that end up messing up your entire layout

Sidebar Below Content Error Solutions:

a. Close all div elements
In most cases, pen div elements are responsible for this error. Close all open div elements and eliminate extra div elements that pushes the sidebar outside the wrap element. Use a tool such as W3 Validator to check if your HTML code could be the cause of this error.

b. Fix your CSS
Improper width ratios will mess up your layout in turn placing your sidebar below the content area. You need to keep things in proportion. For instance, if your main container is 920px in width, allocate 620px to your content and 250px to your sidebar. Leave the remaining 50px to margins and what not. Just keep things proportional. Another thing, be careful when using the float property.

9. WordPress Admin Displaying Improperly

Have you ever logged into WordPress only to find your WP Admin Dashboard all over the place? What I mean it the links are arranged improperly because the dashboard is rendering without CSS.

Admin Display Error Causes:

  • Proxy and Firewalls that black CSS files
  • Corrupted admin menu plugins

Admin Display Error Solutions:

a. Ensure you’re not behind a proxy or firewall
If you’re behind a proxy or firewall (maybe you’re accessing your website from work), try accessing your dashboard elsewhere without proxies or firewalls. You can also try purging your firewall and proxy cache and see if that works.

b. Update/Deactivate admin menu plugins
If you are getting this error after installing a plugin such as Lighter Menus and Admin Drop Down Menu for your admin menu , try updating (re-installing) it. If this WordPress error persists, deactivate the plugin.

10. Connection Timed Out Error

If your WordPress website lives on an overburdened shared server, you will see this WordPress error more often than not. The following problems are responsible for this error.

Time Out Error Causes:

  • Heavy plugins
  • Theme function errors
  • Exhausted PHP memory limit

Time Out Error Solutions:

  • Deactivate the plugins you installed recently or reset your plugins folder
  • Increase your PHP memory limit
  • Switch to the Twenty Twelve theme to determine if the problem lies in your theme

11. Warning: Cannot Modify Header Information – Header Already Sent By

This is yet another common WordPress error that troubles many WordPress users, especially beginners. If you do encounter this error, you will usually see something similar to this:

Warning: Cannot modify header information - Header already sent by (Output started at /blog/wp-config.php:34)

That last part (Output started at /blog/wp-config.php:34) tells you exactly where your error is stemming from.

Cannot Modify Header Error Cause:

  • Presence of white (blank) spaces in the affected file (in our case above, that would be wp-config.php)

Cannot Modify Header Error Solution:

You’ll need to remove the blank spaces. To get rid of this WordPress error:

  1. Download the affected file (e.g. wp-config.php) via File Manager or FTP
  2. Open the file in your favorite editor (e.g. Notepad++)
  3. Remove all spaces before the first <?php (The first <?php should be in the first line)
  4. Remove all spaces after the closing ?>
  5. Save your file

12. The Plugin Won’t Delete Error

Some plugins (and you want to stay clear of such plugins) come with hidden files that become a pain in the neck when you want to delete the plugin. This is a good reason to only download plugins (and themes for that matter) from reputable websites you trust. The problem is you can’t delete the plugin via WordPress Admin and even if you delete the plugin’s folder via File Manager (or FTP), the plugin still appears. Magic? No. Here is the…

Delete Plugin Error Cause:

  • The plugin came with hidden or nested files

Delete Plugin Error Solutions:

a. Obtain plugins from trusted sources
Don’t go picking up plugins from all over the place. If you would like to purchase a well-coded plugin, go with reputable sources such as CodeCanyon or WPExplorer. If you’re after free plugins, check out WordPress plugin repository. Prevention is better than cure, right?

b. Deleting the plugin using Secure Shell (SSH)
This solution will only work if you have SSH access to your WordPress site. This is what to do. Login into your blog using SSH and navigate to “../wp-content/plugins/“. Use the Is -aI command to list all your folders, and finally delete the problematic plugin using the rm (folder name) command.

13. WordPress Posts Returning 404 Error

It is frustrating to access every part of your WordPress website but the posts. Every time you visit a single post, you get a 404 error page – and it’s a great pain because posts are the bones and flesh of any WordPress blog.

404 Error Page Cause:

  • Problem with your permalink settings

404 Error Page Solutions:

a. Save your permalinks
This WordPress error is easy to resolve so don’t panic – you readers will be able to read your posts in no time. Just go to Settings -> Permalinks and hit the Save Changes button.

b. Fix your .htaccess file
If fixing your permalinks does not solve this error, it is time to edit your .htaccess file manually. Navigate to your WordPress root directory and download the .htaccess file. If it doesn’t exists, create a blank text file and save it as .htaccess. Add the following code to the .htaccess file:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

Save and upload the .htaccess to the same location.

14. WordPress Memory Exhausted Error

You know you’ve encountered this error when you see the white screen of death or this error message:

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 2348617 bytes) in /home/username/public_html/your_site/wp-includes/plugins.php on line 36

Memory Exhausted Error Cause:

  • A plugin or script is eating up your memory

Memory Exhausted Error Solution:

The easiest answer is to simply increase your allocated memory. To do this, open your wp-config.php file (which is found in your website’s root directory) and add the following code:

define ('wp_memory_limit', '64M');
NOTE: You don’t have to download the file (or any other file) when using the File Manager. You can edit the files right in the File Manager. Talk to your web host if you cannot find the edit option.

15. Fatal Error Undefined Function is_network_admin

I’ve decided to end this post with a simple but very common WordPress error.

Undefined Function is_network_admin Fatal Error Cause:

  • Failed auto-update

Undefined Function is_network_admin Fatal ErrorSolution:

Further Assistance/Resources

If we weren’t able to solve your error or your specific error wasn’t mentioned in this post you can find a list of really great resources below with some more solutions to common WordPress errors and their fixes. If you still can’t find a solution you could always try contacting your webhost to see if they can assist you! WPEngine has been there for us on more then one occasion when we couldn’t fix the issue ourselves!


Here we are. We just revealed 15 most common WordPress errors and showed you how to solve them. We hope this post will come in handy when you encounter a WordPress error. Bookmark this resource (you will most likely need it at some point – although we hope you don’t) and please tell us how you fix common WordPress errors on your website, especially if you have a better and quicker solution to one of the common WordPress errors.

Mastering WordPress Meta Data: Querying Posts and Users by Meta Data


In order to customize what posts WordPress returns based on meta fields, we need to use WP_Query and specify a meta_query. If, for example, we had a custom post type called ‘films’ that had a custom field called ‘director’ we could query for films whose director was a director of one of the three Star Wars films.

Take a look at the code below and see if you can use your mastery of arrays that you gained in the last part to understand what is going on with the meta_query, which I will break down what is going on under the code.

As you can see we have an array of director’s names nestled inside of three other arrays. Let’s take it apart, piece by piece.

First, we start an array for our WP_Query args. After our first argument ‘post_type’, we begin an array to house our meta_query arguments.

Inside of that we specify which key to look for–in the case ‘director’. We also provide an array of values to search for in that key.

The last argument is how to compare those values, in this case we specify “IN” to retrieve any posts with these values in the key director.

What if we wanted films that where directed by a director of a Star Wars film, but wan’t to exclude the Star Wars Prequels? We can just add another array of arguments to our meta_query, but this time for value use an array of those films titles for the key film_title and for compare, use ‘NOT LIKE’ to exclude post that have these values in the film_title field.

Now WordPress will look for films by these three directors, whose title is not one of the three prequels.

So far I’ve shown you how to use WP_Query to find posts that have specific values for a custom field, but not how to show those fields.

Showing these fields is pretty much the same as before, but instead of using get_the_ID() to specify ID for get_post_meta() we specify it in an object context. So in our loop, which you can see below, the ID is retrieved a little differently using $query->post->ID.

Just like in the last part when we used WP_Query to find posts with certain values for various custom fields, we can use WP_Query‘s user table equivalent WP_User_Query.

For example, if we had a custom field called subscriber_level and wanted to find only those users who had the subscriber level of extra_special or super_special we could, much the same way we searched for films directed by the three directors of the Star Wars films:

Just like with WP_Query, we can combine different comparisons to further control which users our query returns. This next example combines the last query with a a query, this time of the wp_users table itself for any users whose names are Luke, Han or Leia.

In this series you’ve been introduced to WordPress meta data and learned some lessons about core PHP concepts along the way.

You’ve learned how to get the values from the fields that store post and user meta data and how to construct queries for posts and users based on meta values. With this knowledge you can are prepared to work with a few custom fields and on your way to using WordPress as a complex content management system.

How to create a WordPress location based search

I’ve done this a few times in the past but yesterday I decided to write these notes for a colleague to show how to construct a location based search for a new WordPress site he is developing. Essentially to create a location search, in this case for Property sales, we need to override the standard WordPress search with our own custom query. The following is split into sections. It’s written mostly in note form but it should be easy enough to follow. If you have any questions by all means comment and I’ll answer as best as I can.


Create a new custom post type called ‘property’ which will serve as the location for the data keeping it away from the other content on the site.

Custom fields

I use Advanced Custom Fields for all of my projects these days but by all means use your own plugin or method. As long as the data is stored in wp_postmeta then this tutorial is still valid. Create something similar to the following fields in your system. These aren’t really referenced specifically later on but are a good start for search fields for this sort of site.

  • Beds (select, fixed number of options)
  • Baths (select, fixed number of options)
  • Price (number field)
  • Address (separate fields unless you want to split them manually)
  • Type (select, predefined, multiselect?)
  • Status (select, predefined… under offer, sold, available?)

Custom data

On saving a new/exsiting property post type item you need to geocode the address and save the resulting latitude and longitude into the wp_postmeta table. Use the following page to help you with this:

Use the ‘book’ example looking for the ‘property’ post type almost verbatim. It will show you how to trigger a PHP function on the saving of a new or existing item of content using the correct post type. You then need to Geocode (convert to latitude and longitude) the address string from the POST array and save in postmeta per above. The following page will help you with that.

If you aren’t familiar with how to save to postmeta then the following will help:

update_post_meta($post_id, 'latitude', $latitude);

Build the search form sidebar

This can be done either in raw PHP in sidebar.php (or somewhere in the theme) or as a widget (latter method preferred for sidebars as makes it portable). If widgets then the following will help significantly as the code sample is more or less exactly what you need:

Copy the code from the section titled ‘Example’. This will register a widget on the system which you can drag into one or more sidebars in Appearance > Widgets

Setting up a sidebar is here:

If you are using the Bones theme (my preference) then it has several set up out of the box. A sidebar has a name which you use to put the contents onto the site. The code is simply:


It will echo by default and outputs nothing if no widgets so nice and easy really

Build the search form

You can do in HTML/CSS as normal hard coding the values of the search or pulling from $_GET which could be where you are advised to send the data through (means you can directly link via URL to a search result rather than POST which is less portable). The form action to use for a search in WP is /?s= which will activate the search template. ‘s’ is the querystring parameter for a search term. You can perform a search without it.. A handsome chappie wrote a code sample you can use:

Perform the search

search.php in your theme powers the search results as you might know. The query itself can be done anywhere so use this for layout purposes. There should be ‘the loop’ in this file as normal which is designed for search results. Before ‘if (have_posts()): the_post();’ add a PHP function call or your own to something you have defined in functions.php or simply dump your search code into search.php.. there is no ‘wrong’ way to do it.

The trigger for the search is a WP function ‘query_posts()’. It will override the array of data that ‘has_posts’ has to work with and you can use the native output loop/functions to display the results.

Constructing a custom search would be a case of building an array and passing to query_posts. You can get most of the search done this way and then split into a bit of SQL perhaps for the location based side of things. I shall go into that later.

The resource you need to map the majority of the fields would be:

WP Query is the class which WP uses at the back of query_posts but using the latter function sets up globals which make WordPress behave differently in ‘the loop’. For searching on data stored in postmeta you would need to use ‘meta_query’, taxonomies use ‘tax_query’ and general stuff like search you just pass as attributes to the array. Examples as follows which you can break down and use if you like:

function cf_custom_search_query() {
	global $wp_query; //not sure we need this
	$arr = array();
	$author = cf_get('author'); //cf_get is a wrapper on if (isset(something)) return something; else return false;
	$genre = cf_get('genre');
	$price_from = cf_get('price-from');
	$price_to = cf_get('price-to');
	$paged = get_query_var('paged'); //wp function. copy verbatim
	$arr['post_type'] = 'property'; //post type slub
	$arr['post_status'] = 'publish'; //published only as opposed to draft or private
	$arr['paged'] = $paged; //sets the page number to show.. just leave this as is
	$condition = array();
	foreach ($_REQUEST as $key=>$value) {
		if (substr($key, 0, 5) == 'cond-') {
			$condition[] = substr($key, 5); //for multi select checkboxes
	if ($val = cf_get('s')) {
		$arr['s'] = $val; //s is the actual search term
	$meta_query = array();
	if ($price_from || $price_to || $author) { //meta query is for items in post_meta. we can only pass a single array although the array can have multiple conditions
		if ($price_from && $price_to) {
			$meta_query[] = array(
						'key'     => '_price',
						'value'   => array($price_from, $price_to),
						'type' => 'DECIMAL',
						'compare' => 'BETWEEN'
		} else if ($price_from) {
			$meta_query[] = array(
						'key'     => '_price',
						'value'   => $price_from,
						'type' => 'DECIMAL',
						'compare' => '>='
		} else if ($price_to) {
			$meta_query[] = array(
						'key'     => '_price',
						'value'   => $price_to,
						'type' => 'DECIMAL',
						'compare' => '<='

		if ($author) {
			$meta_query[] = array(
						'key'     => 'author',
						'value'   => $author,
						'type' => 'CHAR',
						'compare' => 'LIKE'
		if ($meta_query) {
			$arr['meta_query'] = $meta_query;
	if ($genre && $genre != '-') { //this is a custom taxonomy. so we pass the category slug (or an array of slugs) from a category.
		$arr['tax_query'][] = array(
			'taxonomy' => 'product_cat',
			'field'    => 'slug',
			'terms'    => $genre,
	if ($condition) { //as above. another custom taxonomy
		$arr['tax_query'][] = array(
			'taxonomy' => 'condition',
			'field'    => 'slug',
			'terms'    => $condition,
	if (!$sort = cf_get('sort_order')) {
		$sort = cf_session('sort_order', 'price_low');
	if ($sort) {
		if ($sort == 'price_low' || $sort == 'price_high') {
			$arr['orderby'] = 'meta_value_num';
			$arr['meta_key'] = '_price';
			$arr['order'] = 'ASC';
			if ($sort == 'price_high') {
				$arr['order'] = 'DESC';
		} else {
			$arr['orderby'] = 'title';
			$arr['order'] = 'DESC';
			if ($sort == 'abc') {
				$arr['order'] = 'ASC';
		$_SESSION['sort_order'] = $sort; //so it's saved for next time if they go elsewhere and come back
	query_posts($arr); //performs the query and sets up the globals

Performing a location based search

On search we have ‘s’ or ‘location’ depending on how you built your form. Up to you which field you use but perform the same Geocode on the fly as you did for the save_post step above. This will give you a latitude and longitude to search on. To get into the actual SQL of a search you would want to implement something like the following: //to add to WHERE //to add to FROM

A handy usage conversation to help with the above:

This is a good resource giving you all of the filters you can use to get access to the SQL of the main query:

Make sure to wrap your add_filter and remove_filter calls in is_search() which means you only require the LAT/LONG calculation to be done in search based queries.. or just only add/remove the filter in your search function defined in functions.php or search.php and only called on a search.. making sure to remove once used.

if (is_search()) { 
	add_filter('posts_where', 'my_posts_where'); 
	//.. and so on
	//perform search function
	remove_filter('posts_where', 'my_posts_where'); 
	//.. and so on 

The remove is just housekeeping, however, if you don’t remove the filter(s) then the next time you run query_posts in that same page load the same filters will be added which might mess with the result unexpectedly. To put this together you need to join in two instances of wp_postmeta or $wpdb->postmeta (in case wp_ is not the table prefix) making sure to alias uniquely:

add_filter('posts_join', 'my_posts_join');

function my_posts_join($sql) {
	$sql .= ' JOIN ' . $wpdb->postmeta . ' my_join1 ON (' . $wpdb->posts . '.ID = my_join1.post_id AND my_join1.meta_key="latitude");
	return $sql; 

And in posts_where:

add_filter('posts_where', 'my_posts_where');

function my_posts_where($sql) {
	$sql .= ' AND my_join1.value = "blah" '; //always start AND because it will be appended onto the main query and you can use the aliases defined in the post_join above
	return $sql; 

You can use the geocode values for the location entered via $_GET and then write the SQL to return the correct result based of something like this example:

The section titled ‘Finding Locations with MySQL’ gives the query and some useful advice.

Get a brew and put your feet up!

15 Easy Ways To Speed Up WordPress

WordPress is a great platform. One weakness that it suffers from, however, is it can be quite slow. Without taking the right precautions, you could end up with a sluggish site. That’s not only a hassle for repeat visitors but will cause you to lose subscribers and customers.

In this quick post, I’ll cover all of the best ways that I’ve found to consistently speed up WordPress.

Why WordPress Site Speed Matters

When a person lands on your site for the first time, you only have a few seconds to capture their attention to convince them to hang around.

Get ready to lose sleep at night: according to a report by the Microsoft Bing search team, a 2-second longer delay in page responsiveness reduced user satisfaction by 3.8%, increased lost revenue per user by 4.3%, and a reduced clicks by 4.3%.

If your site takes too long to load, most people are gone, lost before you even had a chance.

Not only that, but Google now includes site speed in it’s ranking algorithm. That means that your site’s speed effects SEO, so if your site is slow, you’re now losing visitors from impatience and reduced rankings in search engines. Yikes.

Let’s fix that.

How To Speed Up WordPress

As a side note, these are not ordered by importance or any criteria, I’ve just gathered everything I’ve learned around how to speed up WordPress page loads and listed them all here.

I guarantee that using even a few will help speed up your site.

1. Choose a good host

When starting out, a shared host might seem like a bargain (“Unlimited page views!”). It comes at another cost: incredibly slow site speed and frequent down time during high traffic periods.

If you plan on publishing popular stuff, you’re killing yourself by running your WordPress site on shared hosting.

The stress of your site going down after getting a big feature is enough to create a few early gray hairs: don’t be a victim, invest in proper hosting.

The only WordPress host I continually recommend is…

WP Engine managed WordPress hosting

My sites are always blazingly fast, never have downtime when I get huge features (like when I was featured on the Discovery Channel blog!), and the back-end is very easy to use.

Last but not least, support is top notch, which is a must when it comes to hosting. Take it from someone who’s learned that the hard way.

Head on over to the WP Engine homepage and check out their offerings, you’ll be happy you did.

2. Start with a solid framework/theme

You might be surprised to here this, but the Twenty Fifteen “framework” (aka the default WP theme) is lightweight and quite speedy.

That’s because they keep the “guts” simple; compare that to bloated frameworks which have tons of features that you will never use, slowing your site to a crawl.

From my experience, the fastest loading premium framework is definitely the Thesis Theme Framework. It surpasses the basic WordPress themes by being far easier to customize.

It’s an incredibly solid framework that won’t slow you down with excess plugins or custom edits. Make the changes right from the theme and avoid bloat, hoorah!

3. Use an effective caching plugin

WordPress plugins are obviously quite useful, but some of the best fall under the caching category, as they drastically improve page loads time, and best of all, all of them on are free and easy to use.

By far my favorite, bar none, is W3 Total Cache, I wouldn’t recommend or use any other caching plugin, it has all of the features you need and is extremely easy to install and use.

Simply install and activate, and what your page load faster as elements are cached.

4. Use a content delivery network (CDN)

All of your favorite big blogs are making use of this, and if you are into online marketing using WordPress (as I’m sure many of my readers are) you won’t be surprised to here that some of your favorite blogs like Copyblogger are making use of CDN’s.

Essentially, a CDN, or content delivery network, takes all your static files you’ve got on your site (CSS, Javascript and images etc) and lets visitors download them as fast as possible by serving the files on servers as close to them as possible.

I personally use the Max CDN Content Delivery Network on my WordPress sites, as I’ve found that they have the most reasonable prices and their dashboard is very simple to use (and comes with video tutorials for setting it up, takes only a few minutes).

There is a plugin called Free-CDN that promises to do the same, although I haven’t tested it.

5. Optimize images (automatically)

Yahoo! has an image optimizer called that will drastically reduce the file size of an image, while not reducing quality.

However, if you are like me, doing this to every image would be beyond a pain, and incredibly time consuming.

Fortunately, there is an amazing, free plugin called WP-SmushIt which will do this process to all of your images automatically, as you are uploading them. No reason not to install this one.

6. Optimize your homepage to load quickly

This isn’t one thing but really a few easy things that you can do to ensure that your homepage loads quickly, which probably is the most important part of your site because people will be landing there the most often.

Things that you can do include:

  • Show excerpts instead of full posts
  • Reduce the number of posts on the page (I like showing between 5-7)
  • Remove unnecessary sharing widgets from the home page (include them only in posts)
  • Remove inactive plugins and widgets that you don’t need
  • Keep in minimal! Readers are here for content, not 8,000 widgets on the homepage
Overall, a clean and focused homepage design will help your page not only look good, but load quicker as well.

7. Optimize your WordPress database

I’m certainly getting a lot of use out of the word “optimize” in this post!

This can be done the very tedious, extremly boring manual fashion, or…

You can simply use the WP-Optimize plugin, which I run on all of my sites.

This plugin lets you do just one simple task: optimize the your database (spam, post revisions, drafts, tables, etc.) to reduce their overhead.

I would also recommend the WP-DB Manager plugin, which can schedule dates for database optimization.

8. Disable hotlinking and leeching of your content

Hotlinking is a form of bandwidth “theft.” It occurs when other sites direct link to the images on your site from their articles making your server load increasingly high.

This can add up as more and more people “scrape” your posts or your site (and especially images) become more popular, as must do if you create custom images for your site on a regular basis.

Place this code in your root .htaccess file:

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

You’ll notice I included my feed (from FeedBurner), you’ll need to replace it with your feed’s name, otherwise your images won’t appear correctly there.

9. Add an expires header to static resources

An Expires header is a way to specify a time far enough in the future so that the clients (browsers) don’t have to re-fetch any static content (such as css file, javascript, images etc).

This way can cut your load time significantly for your regular users.

You need to copy and paste the following code in your root .htaccess file:

ExpiresActive On
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpg A2592000
ExpiresByType image/jpeg A2592000

The above numbers are set for a month (in seconds), you can change them as you wish.

10. Adjust Gravatar images

You’ll notice on this site that the default Gravatar image is set to… well, nothing.

This is not an aesthetic choice, I did it because it improves page loads by simply having nothing where there would normally be a goofy looking Gravatar logo or some other nonsense.

Some blogs go as far to disable them throughout the site, and for everyone.

You can do either, just know that it will at least benefit your site speed if you set the default image (found in “Discussion”, under the settings tab in the WordPress dashboard) to a blank space rather than a default image.

11. Add LazyLoad to your images

LazyLoad is the process of having only only the images above the fold load (i.e. only the images visible in the visitor’s browser window), then, when reader scrolls down, the other images begin to load, just before they come into view.

This will not only speed you page loads, it can also save bandwidth by loading less data for users who don’t scroll all the way down on your pages.

To do this automatically, install the jQuery Image Lazy Load plugin.

12. Control the amount of post revisions stored

I saved this post to draft about 8 times.

WordPress, left to its own devices, would store every single one of these drafts, indefinitely.

Now, when this post is done and published, why would I need all of those drafts stored?

That’s why I use the Revision Control plugin to make sure I keep post revisions to a minimum, set it to 2 or 3 so you have something to fall back on in case you make a mistake, but not too high that you clutter your backend with unnecessary amounts of drafted posts.

13. Turn off pingbacks and trackbacks

By default, WordPress interacts with other blogs that are equipped with pingbacks and trackbacks.

Every time another blog mentions you, it notifies your site, which in turn updates data on the post. Turning this off will not destroy the backlinks to your site, just the setting that generates a lot of work for your site.

For more detail, read this explanation of WordPress Pingbacks, Trackbacks and Linkbacks.

14. Replace PHP with static HTML, when necessary

This one is a little bit advanced, but can drastically cut down your load time if you are desperate to include page load speeds, so I included it.

I’d be doing this great post injustice if I didn’t link to it for this topic, as it taught me how to easily do this myself, in a few minutes.

So go there and check it out, it wrote it out in plainer terms than I ever could!

15. Use CloudFlare

This is similar to the section above on using CDN’s, but I’ve become so fond of CloudFlare since I discussed it in my best web analytics post that I’ve decided to include it separately here.

To put it bluntly, CloudFlare, along with the W3 Total Cache plugin discussed above, are a really potent combination (they integrate with each other) that will greatly improve not only the speed, but the security of your site.

Both are free!

Thanks for reading! Please share this article if you enjoyed it.


Step-By-Step Guide to Index your WordPress website by Google

Who doesn’t want more organic search traffic to their sites? The definite answer is none.

Organic search is absolutely critical as it is the source of 64% of the total traffic to a website. There will be no value of this number if search engines don’t index your site. It’s as simple as that.

What is indexing of a website?

Indexing is referred to search engine recording your web pages and showing it up every time a user look for the information similar to your web pages. Mostly, when a bot of search engine arrives at your website, it starts crawling. Based on ‘noindex’ or ‘index’ meta tags, the bot adds pages in the search engines with index tags.

How do you get your website indexed by all major search engines?

There are two ways to do that. One is to create a WordPress website and sit back and relax, while indexing happens naturally (which will take a long time) and the other one is putting some efforts and make it happen. If you’re ready to implement the second method, then continue reading.

1.     Understanding the working of search engines:

You won’t be able to do much if you don’t know how exactly the major search engines like Google Yahoo, Bing and other works. Almost all search engines count on spiders that use algorithms to do the indexing which is not difficult to understand. The work of spiders is to find out the new content on the internet and figure it what it is all about. A new content could be from anywhere, an existing page, a new site or a new blog.

In earlier days, you could force a bot to index and rank your webpages based on how many times a particular search keyword is used. But today, doing this will get you penalized. It doesn’t mean that keywords no longer helps a website getting indexed on the search engines but with that, you have to take care of few other things like social signals, valid codes, quality incoming links and much more. All of this won’t matter until spiders tell the search engines where to begin and that’s when indexing comes in.

Imp: Spiders will note down every time a new document and changes added to a webpage, and it’ll process it and note down the location. When a user searches for the information associated with the similar keywords, Spiders get to the work and find the links on pages and add them to the list of crawled pages.

So, it’s always important to check a recently published article to know that Google has already found it. You can use a to search the same and ensure your page is easy to find.

2.      Add articles and blogs

Write in-depth and high quality blogs regularly and you’ll see why it’s worth writing. High percentage of the retailers say their customers are from the blog posts, and more than 60% of the people buy products or services based on the blogger’s recommendations.

It’s very simple and for every industry, niche and business. Just create a blog post about a product, add some high pixel images and links to the page as this will help product page to get indexed and crawled by search engine bots.

Content Strategy

As we have already mentioned the value of blogs, it’s to your own benefit to have a good content marketing strategy. A well-written content helps you focus on increasing conversions of the leads. It doesn’t have to be difficult or complex. Simply:

  • Write GPs (Guest posts) and submit it the sites similar to your niche
  • Create PRs (Press releases) and publish them on PR sites.
  • Blogs on article directories.
  • Prepare videos and host on major platforms like Youtube or Vimeo.

Note: Don’t try shortcuts by posting your content on spammy sites as Google will then consider your site as spammy too.

3.      Use Google Analytics

You need basic analytical tools to know the performance of your website and what better than Google analytics suffice to this need?

Setting up Google Analytics suggests Google that your website is on the internet and may help in triggering the indexing and crawling process. It’s the additional advantage, but you need it for knowing the total number of user visits, the time length spent on a page, pageviews and much more.

Also, you can use it for advanced tricks like tracking conversions and setting goals.

4.      Submitting To Google Search Console (GSC)

Image “google search console” Here

GSC is a mishmash of SEO tools and reporting that offers configuration and data to control your website by providing you direct insight on how Google is indexing your website. Check out following reasons why should you use this tool as an imperative part of your website.

Helps bloggers:

  • To monitor visibility on search engines and ‘404 not found’ errors.
  • To know the keywords, their sites are ranking for.
  • In Improving the sire indexing and crawling
  • To monitor if a website is indexable by bots
  • Issues that need fixing like HTML improvements
  • Submitting the sitemap to Google

5.      Submitting Website’s URL to Search Engines

On Google, you can submit your website’s URL by logging in to your account and navigate to “submit URL” found in Webmaster Tools. Then enter the URL and click on the option that says, “I’m not a robot”. Now, click submit and your website will get submitted to Google. Similarly, you can add the URL to Bing which will automatically submit it to the Yahoo.

6.      Sitemap

Sitemap is a list in XML format of every page which let the search engines know that something’s changed when you upload a new page or edit a page on your website. They significantly help your website to get crawled quickly. If you have submitted a Sitemap, it means Google knows about your URL. You can follow instructions of Google on how to add an HTML file. Once you have added your website, go to the Dashboard, then to that website and click on “Sitemaps” and add it on your website.

There is no restriction on how many times you can submit the sitemap to Google but just ensure that every time you are updating the content or images, add a sitemap.

7.      Social Media

It is one of the most effective methods to generate the traffic on your website. You can start with StumbleUpon, Facebook, Twitter, Google Plus, and the other main search engines for faster indexing of your content. Not only social media pages but also create social media profiles on YouTube channels, LinkedIn profiles or company pages, Facebook and Twitter pages and Pinterest profiles to add links that point to your website.


Perhaps, you know that if you submit a URL to a blog directory, it’ll help your site indexed by not and will easily be found by potential users, and if you know the right way to do it, it’ll make indexing quicker than usual. Submit your URLs to only best authority and industry blogs if you need to get in the top search results of search engines. Not only it will open up your content to new traffic but also helps you with incoming links that are easy to crawl and index by search engines. Isn’t that you need? Also, You might want to know about the TopRank and Technorati which are two of the top blog directories across the world to submit your RSS feed and blogs

Now, you have seven efficient methods for getting your website indexed by search engines to drive more and more traffic.

It isn’t an exhaustive list as there are techniques like bookmarking, commenting on various forums and much more. The point is there are various techniques and methodologies arises on the daily basis when it comes to search engine ranking. So, stay updated and use everything you can for better ranking of your website.