Wordpress tricks

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

MYOB Accountright API Integration With WordPress/PHP

Since a year or so, we are doing multiple projects on integration of wordpress with MYOB Accountright Live API. The projects were difficult in the beginning, because the API docs do not give much details about problems encountered in interacting with API using PHP.

The first project we did was integrating Membermouse plugin with Accountright API. Our custom MYOB plugin created invoice for every new Membership and a renewal. Since the memberships were subscriptions, we had to keep a track of dates and billing period. Dealing with Membermouse was a pain, it has a lot encrypted code in it, which makes it close to impossible for a developer to see its workflow. Working on it with dedication, we were able to complete and deliver the integration to client. It worked perfectly 🙂

After this project we had several others, where we integrated Woocommerce with Accountright API. This was overall a very good and smooth experience. Woocommerce is open-source and has lots and lots of documentation which makes it easy to work with its API and functions. Whenever a customer ordered a […]

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 found a lot of plugins which can improve search but found glitches in each of it. I decided to write my own solution. 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!

SpeedUp Your Website

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

Boost Google Pagespeed Rank
Site Optimization is a major consideration these days. This is because if your site loading speed is not fast enough, 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 can I 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 . Out of these two I have found GTMETRIX to be more detailed and solid.

Why is my website slow?
When you have tested your website loading speed then you might wonder what is making it slow. Now look at the list of suggestions that are given by the two speed testing […]

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