Wordpress tricks

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

Search by Exact Words in WordPress Search

Improve WordPress Search to Make it Search Exact Words.
The native wordpress search, does not look for exact complete words. It means that when you look for ‘Los’ you also get words like ‘lost’ ‘loser’ in search results. I needed a search which could look for exact word in posts. I implemented wordpress search for exact word in post titles using this code in functions.php.

You can change this to search for exact words in titles plus content both, by modifying the line 18 to
Method 1:

The rest of code will remain same. Using the above snippets you will be able to improve wordpress search and make it exact word search.

I have come across another simpler solution, which be helpful, but the snippet posted above can be customized easily as much you need. So I would use method 1.

Method 2:

If you need to highlight search words, read here. I hope you like these wonderful snippets, happy coding!

Speed Up Your Site

Are you looking for “Best wordpress plugin to speed up site” or “wordpress site speed optimization plugin” ? Good news is, you have come to the right place!

Boost Google Pagespeed Rank
Site Optimization is a major consideration these days. If your site loading speed is not fast, you are losing a lot of visitors hence ad revenues. So, website owners are pretty much concerned about speed now. We will try to answer the common questions website owners have about speed:

How to know the speed of my Website?
There are some utilities available on the internet for free, where you can just type in your url and test your speed. The ones I use are Google PageSpeed Insight and GTMetrix

Why is my website slow?
When you have tested your website loading speed, you might wonder what is making it slow. The best way to know this is to look at suggestions that is given by the two speed testing sites. They will tell you the problems you have that make you slow and what can be done to fix them.

My Website is slow, what […]

Remove Slug from Custom Post Type URLs

Many times, you would like to remove the custom post type slug from urls. You don’t want frontend users to see you custom post type slug and to know you are using one. I kept looking for solutions, modified rewrite rules and did lots of things finally found a very easier solution. This solution works for hierarchical posts and non-hierarchical both. It also removes parent slug from hierarchical posts.  I hope this would help you guys. Here is the code.

The above code snippet will be put into your functions.php and it will remove slugs from all post urls. So where ever in the template you are displaying the_permalink() . But clicking those links you will get a 404, page not found if you don’t set the right query vars which are set in code given below:

So adding the above two snippets to funtions.php will remove custom post type slugs from urls. But last thing is:

don’t forget to replace your_custompost_type_slug in above code with your custom post type slug.  Happy coding!

courtesy:<a href=”http://ryansechrest.com/2013/04/remove-post-type-slug-in-custom-post-type-url-and-move-subpages-to-website-root-in-wordpress/”>Ryan Sechrest. </a>

WordPress Display Posts From Category

A lot of times we need to display posts from a certain category on a page or a part of page. This is possible by using a bit of code in the relevant template file. For example if you need to display the posts from a category on homepage then edit the index.php (or any other file which has been set up as homepage in dashboard settings).
Display Posts by Category
Its easy to display posts by category using ‘wp_query’ object in code. You can easily use the arguments of the ‘wp_query’  to pass the category id and then display relevant posts. Now question is how to find the catagory id (which is a number) of a certain category. There two ways of doing that:

Two Ways of Finding Category ID in WordPress
1-Click on posts->categories and hover over the category name at the bottom of the screen you will see a link, which has a word call tag_id. See what is the value of tag_id and that gives you the category id.

2-Install the ‘reveal IDs’ plugin and it will show you catgory ID […]

Stylish Showcase WordPress Theme

A  stylish theme by Smart Magazine to showcase cars or any other products you want to show. Its a simple blog theme which can be used for many purposes. A brand new design for 2013.

Demo   Dowload

Display Category Names in Multiple Columns

Sometimes you have a lot of categories, you cannot simply list them down as one column. In such a case you would like to have it displayed in multiple columns. We will use wordpress built-in functions to list categories, so that any new ones are automatically added to the list.
You can display the category names in footer in 2 or columns in your theme. This can be done by using wp_list_categories() and playing with some mathematics. Normally you can find code that displays category names in two columns but this snippet will do it in as many columns as you want. Have a look at this tip and you will love it!!

source:http://www.bloggingpro.com/archives/2010/01/15/how-to-display-your-wordpress-category-list-in-multiple-columns/

Adding Category Images To posts

Sometimes you would like to add a specific featured image to post if it belongs to a specific category. You would like the posts from one category to display an image when it does not have an image attachment with itself, so if an author leaves out or forgets a to put a featured image, you don’t have a blank image for that post and a category image is displayed automatically. This can be done very easily in wordpress. Here are the steps

1-First save images or icons for each category with their name. For example for news category save a picture news.png, for economy category save economy.png and so on. Save all of them in images folder of your active theme.

2-Then in your template files where ever you want to show featured images write this code.

and you are done!

Another way to add images to category posts is by using plugin. A plugins you can use for this purpose is
Category Thumnail

Disable or Disallow Comments in WordPress

You can disable comments in wordpress easily. The trick is to go to Settings -> Discussion -> then uncheck option “Allow people to post comments on new articles”

This setting applies to all new posts that will be published from now onwards. To disable comments from posts that have been published.

Posts -> select all then click “Edit” under bulk actions and click apply >> choose “do not allow” next to comments and hit update posts.

If you don’t want the comment form to show on any post or pages then locate all occurrences of the code below and remove it.

I you don’t want the text “Comments off” to be displayed then look for wp-icludes/comment-template.php and open it in a notepad. Change the line

to

5 ways to Protect Your WordPress Site From Spam

Some days after you launch your website, you will notice a lot of comments from spam bots. These are very annoying and often target a certain post of the blog. The comment title consists of links and the body has some spam links and text. Spammers not only spam in comments they also steal your website content and spread it all over the web that is another reason why its important to protect wordpress from spam.
There are two kinds of method used by spammers:

Automated spam-bots : – Spammers use such as program and tools (robots) that can automatically submit large numbers of spam comment to numbers of blog in no time.

Manual Spam : -Well in this case spammers visit your site and manually post their spam comments in the comments field.

Spam Comments are a fact of life for bloggers, and no one can stop Spam Comments 100%, You can only minimize that to a lower level by using some tricks below to fight the spam on your wordpress website.
1-Install Akistmet
First thing you should is , install Akismet. Akismet is great plugin […]