This article is aim to collect all useful tricks / tips / hacks of WordPress. The final goal is to make it a ultimate reference for WordPress users and developers. Therefor this article will be continuously updated. New tricks will added and old tricks might be modified for the latest version of WordPress.

You are welcomed to suggest new tricks or better solutions.

[Updated: Feb 13, 2015]

MySQL Database

Useful SQL Queries for WordPress

WordPress MySQL Database Hacks

Useful SQL Queries for WordPress

1. SQL query for changing SiteURL and HomeURL

You need to update your SiteURL and HomeURL once you changed domain name.

2. SQL query for changing GUID

GUID stands for Globally Unique Identifier. The WordPress team suggests you should never change GUID. But Terrence said, “GUID is used to translate your post or page slug to the correct article absolute path if it is entered wrongly.”

3. SQL query for changing URL in post content

Don’t forget old URLs in your post content.

Actually with tiny tweak, you can use this query to change anything in your post. Check out the following query.

4. SQL query for changing image path in post content

Addiction to the last query, as we know, in HTML, all image paths start with “src=”, you can use the follow query to change all image paths in your posts.

You may also want to change the GUIDs of your image attachments.

5. SQL query for changing URL in post meta

This query will help you to change the URL in post meta.

6. SQL query for changing username

For example, if you want to change the username of “admin” to “newadmin”.

7. SQL query for changing password

For example, if you want to change the password of the user “newadmin” to be “newpass”.

8. SQL query for changing the author of posts

This query will change all oldauthor’s posts to be newautohr’s.

9. SQL query for deleting post revision

Revision is an interesting idea, but not everyone likes it. Because it increases the burden of the database, eventually might make your website slow. Here is an SQL query for deleting all revisions by Lester chan.

10. SQL query for deleting post meta

Some WordPress plugins might store information in the post_meta table. Those information will be there even after you removed the plugins. This query will help you to remove redundant post meta. Make sure you’ve figured out the post_meta_key of the plugin.

11. SQL query for exporting all comment emails with no duplicate

This query will help you to get all commenters’ email from your blog.

12. SQL query for deleting all pingbacks.

Deleting pingbacks will help you to reduce the size of your database.

13. SQL query for deleting all spam comments

This query will help your to delete all spam comments in your database.

  • 0 = Comment Awaiting Moderation
  • 1 = Approved Comment
  • spam = Comment marked as Spam

14. SQL query for identifying and deleting unused tags

After deleting some posts, you might have some tags which associate with no post. This query will help you to identifying these unused tags. Change the SELECT keyword to DELETE, you can delete all unused tags.

Reference: onextrapixel

15. SQL query for disabling comments on older posts

This query will set comment status to closed for posts that are older than “2014-1-1″, edit the date to suit your need.


16. SQL query for deleting comments with a specific URL

This query will help you to delete all comments where the comment_author_url is “spamurl”.


17. SQL query for deleting posts that are older than “X” days.

This query will help you to delete all posts that are older than a certain amount of days. Let’s use 100 days as an example.


18. SQL query for disabling and enabling trackbacks and pingbacks

Enable trackbacks/pingbacks:

Disable trackbacks/pingbacks:

Disable trackbacks/pingbacks before a certain day. We use “2014-1-1″ as an example. By changing “closed” to “open”, you can also use this query to enable trackbacks/pingbacks before a certain day.


 19. SQL query for deleting shortcodes

If you decided not to use a shortcode any more, you can use this query to delete it. Here we use the shortcode “tweet” as an example.


20. SQL query for changing pages into posts

You can use this query to change pages into posts. By exchange the position of “post” and “page”, you can do it vice-versa.


21. SQL query for disabling all WordPress plugins

This query will help you to disable all your plugins. It is helpful when you blog crashes because for one of your plugins.


WordPress Comment Form Customization with Twitter Bootstrap.

WordPress Comment Form in Bootstrap Style

Bootstrap Comment Form WordPress

In order to customize the Comment Form of WordPress, we need to deal with the ‘comment_form_default’ filter. The following code is placed in functions.php of ZackLive theme.

As you can see, we wrap the input field and textarea with a div containing the class ‘form-group‘ from Bootstrap and then use another class ‘form-control‘ to style them.

Next, you might want to style the input field to make it shorter:

Finally, we need to deal with the submit button. Since there is no hook for the submit button, one solution out there is to hide the original one using CSS and add a new one by attaching code to ‘comment_notes_after’. Here is how to do it.

1. in style.css, add the following code:

2. in functions.php, find  $args['comment_notes_after'] = '';  in function ‘zacklive_comment_form()’, change it to be:

There you have a Bootstrap style submit button.

Another solution is to use JavaScript to add the attribute to the button. The advantage of JavaScript is that you don’t need to create another button and you can also apply the same style to the comment reply link.

1. Create a new file, name it like ‘bootstrap-wp.js’.

2. Put the following code into the new file:

3. Enqueue the new file to your WordPress in functions.php, beware of the path of the JavaScript file:

And now you have a Bootstrap style submit button and reply button.

Reference: codecheesewebinspiration

We’ve discussed about Customize Comment_form() in WordPress with the filter: comment_form_defaults. But the problem with comment_form_defaults is that it doesn’t allow you to add class to the submit button which means you can’t style the submit button. For example, I want to use Bootstrap style button for the submit button of my theme No Newz. I can’t make that happen with this filter.

Read More

I’m testing the No Newz theme with WordPress’ Theme Unit Test. Some small bugs were fixed, including Calendar widget, widget with oversize image, long title in Select and columns displaying error of gallery images. These are just tiny things which can be fixed with some CSS styling. But one thing I never noticed before, there is a post which has no title. Therefore you can’t display a link on your post list(index.php) to access that post. As a result, you can’t even open the page of that post. This is kind of a problem.

Read More