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

8 04, 2018

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

18 05, 2018

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. // Search SQL filter for matching against post title only. function __search_by_title_only( $search, $wp_query ) { global $wpdb; if ( empty( $search ) ) return $search; // skip processing - no search term in query $q = $wp_query->query_vars; $n = ! empty( $q['exact'] ) ? '' : '%'; $search = $searchand = ''; foreach ( (array) $q['search_terms'] as $term ) { $term = esc_sql( like_escape( $term ) ); $search .= "{$searchand}($wpdb->posts.post_title REGEXP '[[:<:]]{$term}[[:>:]]')"; $searchand = ' AND '; } if ( ! empty( $search ) ) { $search = "

29 12, 2016

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

13 03, 2014

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. add_filter( 'post_type_link', 'custom_post_type_link', 10, 3 ); function custom_post_type_link($permalink, $post, $leavename) { if (!gettype($post) == 'post') { return $permalink; } switch ($post->post_type) { case 'your_custompost_type_slug': $permalink = get_home_url() . '/' . $post->post_name . '/'; break; } return $permalink; } 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: add_action( 'pre_get_posts',

2 09, 2013

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

18 02, 2013

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

10 11, 2012

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!! <?php // Grab top level categories (depth=1) $get_cats = explode("<br />",wp_list_categories('title_li=&echo=0&show_count=1&depth=1&style=none&hierarchical=0&feed=RSS')); $results_total = count($get_cats); $results_total= $results_total-1; // How many categories to show per list (round up total divided by 5) $cats_per_list = ceil($results_total / 4); // Counter number for tagging onto each list $list_number = 1; // Set the category result counter to zero $result_number = 0;?> <ul class="category_footer_post" id="cat-col-<?php echo $list_number; ?>"> <?php foreach($get_cats as

3 07, 2012

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. <?php if ( (function_exists('has_post_thumbnail')) && (has_post_thumbnail()) ) { the_post_thumbnail('thumbnail'); } else { ?> <img src="<?php bloginfo('url')/images/<?php $category = get_the_category(); echo $category[0]->cat_name; ?>.jpg" /> <?php } endif; } ?> and you are done! Another way to add images to category posts

14 06, 2012

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. <?php comments_popup_link(__('Comments (0)'), __('Comments (1)'), __('Comments (%)')); ?> 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 function comments_popup_link( $zero = 'No Comments', $one = '1 Comment', $more = '% Comments', $css_class = '', $none = 'Comments Off' ) to //change $none = 'Comments Off' to $none = '' function comments_popup_link( $zero = 'No Comments', $one = '1 Comment',

WhatsApp chat