Wordpress tricks

wordpress tricks, tips, code snippets, wordpress plugins, plugin development, useful functions in wordpress, template tags and customization, frontend uploader for wordpress posts

How to add featured Image Support.

Lets talk about another wordpress trick.

Have you ever opened your post editor and found there is no featured image box in it?

A lot will say “yes”

The reason being that wordpress requires you to add theme support for thumbnails manually through your functions.php or some plug-in.

Adding the support manually is very simple. Open the functions.php file which lies in your active theme’s folder and paste this code.

Adding theme support for all post types.
Adding support only for pages.

Adding Thumbnail Sizes
You can add an option so that all thumbnails have an exact size and will be cropped to that size without keeping the aspect ratio of the image by setting a size and setting the third crop parameter to be true, as shown below
For using the thumbnail in theme, there are three functions.

has_post_thumbnail() returns ‘true’ if a thumbnail has been set
the_post_thumbnail() echos a string containing the thumbnail < img alt=”” / > tag
get_the_post_thumbnail() returns a string containing the thumbnail < img alt=”” /> tag

Read more about thumnail on this link

Highlight Search Term in Search Results

Using wordpress native search, you can use this trick to highlight the search term in the title in the search results. This can be done by tokeinizing the title and then assigning a css class to the search word. This css class can be styled with background color to highlight the search word. Use this code in funtions.php

Last but not the least, paste this in your style.css

You can also use this plugin to achieve the same funtionality without writing any code yourself. Hope you like this wordpress snippet 🙂

Use a Default Theme Background for WordPress Theme Options

You can add theme support for background image. If user does not choose an image, a default image will be set as theme background image. Use this code in functions.php

add_theme_support( ‘custom-background’, array(
‘default-image’ => get_template_directory_uri() . ‘/images/default-background.png’,
) );


Beautiful WordPress theme designed by themeforest. Switchable layout, support for background and menus, inventory manager and much more.(premium)
Preview  Info

WordPress Private Message System Plugin


While looking for plugins to implement ‘Private message system’ between users in wordpress, i found a not so-famous but awesome plugin called ‘Cartpauj PM’. The plugin has a very neat code, interface and functionality. The code is based on OOP with nicely defined functions.

You can cal any function anywhere to have a part of functionality of the plugin. The plugin also has a skin/mod available, which has some css, images and nice layouts for plugin’s frontend pages. The cartpauj website has a number of other plugins as well and also a support forum for their plugins.




Author Page – All Comments by an Author

You can create a complete and nice Author’s page which will be displayed whenever someone clicks on an Author’s name link. The trick here is to create an author.php, this page will be displayed whenever you click on an author’s name link.
The Author page for an author can have all posts and comments by an author. To list all comments by an author you can use the code below.

Frontend Posting With Image Uploader

Recently i had to implement frontend posting for the sidebar. I chose Quick Post Widget for this purpose. This plugin has a very flexible UI with a lot of options. The only problem i had was, it used a tab in the visual editor for image attachments, which my client did not like much. He wanted an image uploading field upfront.

So i decided to add a front end image uploader to Quick Post Widget. The file i edited was ‘quick-post-widget.php’. Here are the steps i followed

1- I modified the opening form tag and added enctype to it (this is the form that will displayed on frontend).

2- In the form, before the submit button, added a field of type ‘file’ for images.

3- Added the image upload function to my functions.php so i can also call it later wherever i need.

4- Now i called the above function for quick post widget ‘mypostimage’ field. Added this code just after wp_insert_post was called in the quick-post-widget.php. This code would insert the image as an attachment image for the post.

Below is the screenshot, how the […]

Why Use WordPress For Websites?

“I can’t change content of my website”


“My webmaster isn.t available , i need my company address to be changed!! ”


“I don’t know html, i have messed up my webpage”

If you know someone who owns a small business or personal website, you will hear such cries a lot. After making a static html site, which has no editing or updation capibility, you have a hard time maintaining your website. Changes are needed occasionally and you have to pay webmaster for them every now and then. This causes you a lot of variable cost. What is the solution?

Using CMS for your website saves you from a lot of headache. You now have to pay the deveoper only once. The rest of the things are under your control. The cost of a CMS based website is obviously more than that of static webpage, but it doesn’t hurt since you have almost no variable cost involved in future.

There are many CMS available out there, but decision of choosing one of them is tricky. WordPress is a wonderful CMS for beginners. It is widely used […]

Get Users’ Search Terms

This code is very useful when you want to show the users posts related to their search. Some blog would show pop ups at the bottom using these search terms and will take users to other posts of their blog. Here is a code snippet to get the search terms of your users.