Wordpress tricks

Home/Wordpress tricks

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

23 04, 2012

How to Remove 404 Error from Google Index

We all have experienced errors like "Sorry. 404 page not found " if the resource on that url has been moved.  These 404s errors will go away by themself generally after a week or so, but if your domain has too many 404 Errors floating around in the search engines a few things may happen: 1.Your site’s reputation may be hurt. 2.Your site’s rankings may suffer. 3.Your site may be penalized. 4.Your site may be banned from the index. As you see, a 404-Error page is a killer of SEO campaigns (404-Errors should not be confused with “server not found” or similar errors, in which a connection to the destination server could not be made at all). Somtimes if a page is not removed from following the above steps then it might not be a 404 truly. To test if a page is a true 404 use this tool   Here are steps that can be followed to remove 404. Step #1: Set Up In Google Webmaster Tools To start the process, make sure you’re site is being tracked in

21 04, 2012

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. add_theme_support('post-thumbnails'); Adding support only for pages. add_theme_support(array('page')); 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 set_post_thumbnail_size(150,150,true); 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

28 12, 2016

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 if(!empty($getvars[s])){ $title = get_the_title(); $keys= explode(" ",$s); $title = preg_replace('/('.implode('|', $keys) .')/iu', '<strong class="search-excerpt">\0</strong>', $title); } //To display the title use echo $title; //instead of the_title(); Last but not the least, paste this in your style.css .search-excerpt{ background-color:#ffff00; } You can also use this plugin to achieve the same funtionality without writing any code yourself. Hope you like this wordpress snippet :)

18 04, 2012

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', ) );

18 04, 2012


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

3 04, 2012

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.      

3 04, 2012

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.

18 03, 2012

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). enctype="multipart/form-data" 2- In the form, before the submit button, added a field of type 'file' for images. <label for="attachment">Image: </label> <input id="attachment" type="file" name="mypostimage" /> 3- Added the image upload function to my functions.php so i can also call it later wherever i need. function insert_attachment($file_handler,$post_id,$setthumb='false') { // check to make sure its a successful upload if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) __return_false(); //for use in widgets we include

27 02, 2012

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

WhatsApp chat