Shortcodes in Widgets

written by Tech Sugar ♦ posted in ♦ December 19, 2012

I had an instance the other day where I needed to add a shortcode into a widget area. Normally you would think adding a shortcode in this fashion would work just fine – however that wasn’t the case. After quite a bit of time head scratching I was able to find a solution that would work.

add_filter('widget_text', 'do_shortcode');

This will ensure that the content of the widgets is parsed with shortcodes and those shortcodes also run.

Grouping WordPress Posts in Loop

written by Tech Sugar ♦ posted in ♦ May 4, 2012

I was recently working on a WordPress project that brought up an interesting scenario. It was a game site that featured online, PC and Mac games. Each game type was setup using a custom post type. In this scenario there were some games that were featured in all 3 post types – so essentially 3 posts with the same post_title. The problem was during the WordPress Loop it was showing the same title 3 times in a row (1 for each post type).

The best way to handle this situation is to group the items into one versus displaying the same title 3x’s. To do this WordPress has a great posts_groupby hook. It’s not widely used or known about but worked perfectly in this situation. Here is how you do it.

Below is code that alters the main WP loop by grouping the posts with the same post_title. You can obviously group by whatever you want – whether it be the post_title,  post_category, etc.

add_filter('posts_groupby', 'game_posts_groupby', 11);
// the number 11 is one greater then the amount of posts on the page (I was looping 10 per page)
function game_posts_groupby() { return 'post_title'; }
$posts = query_posts($query_string . '&orderby=title&order=asc' . $type);
remove_filter('posts_groupby', 'game_posts_groupby', 11);

The first line adds the filter posts_groupby. It is calling the function game_posts_groupby which tells WordPress what we want to group our items by. The $posts = line calls our post along with sorting by alpha. Finally we remove the filter on the last line. This is important as it can possibly mess up any other queries you’d have on your page as well.

WordPress has a lot of hidden gems and this hook definitely proved itself.

WordPress How to Display Query Count and Load Time

written by Tech Sugar ♦ posted in ♦ April 30, 2012

One important item that often gets overlooked when putting a site together is the overall load time of your site. As great as WordPress is their are some downfalls that often get overlooked. The core WordPress versions are highly optimized however you must be careful in theme development and adding plugins that you do not cause unnecessary query and load time issues.

To determine how many queries and seconds it takes to load your site open up your footer.php file in your theme and add the following code just before the closing body tag.

<?php echo get_num_queries(); ?> queries in <?php timer_stop(1); ?> seconds.

The get_num_queries() function returns the number of executed query during your page loading while the time_stops displays the amount of time it took to load your page.

If you find that you are having a problem with high query counts try to deactivate plugins, refresh your page and determine if there are any “troublesome” plugins.

Google Analytics: How to Install and Verify Event Tracking Works

written by Tech Sugar ♦ posted in ♦ February 15, 2012

One of the many great features Google provides is their Analytics platform. It is a must-have for any website owner. It provides you with valuable data on visitors to your site, pages visited and other relavent data. One of the underutilized tools is Google Analytics Event Tracking. Event tracking is used to track things such as outbound clicks, video players or any other type of “actionable” items on your website.

We often use event tracking to track outgoing links we want to record click data on. Installation is easy and you can view the Google documentation to learn more.

<a href="#" onClick="_gaq.push(['_trackEvent', 'Outgoing Links', 'Bobs Website', 'HomePage']);">Visit Bobs Site</a>

Once you get the tracking installed I find it important to make sure the click tracking is working. A large majority of the time it will work flawlessly, but there are certain scenarios where there may be issues. Read More »»

WordPress: How to edit “Enter title here” text

written by Tech Sugar ♦ posted in ♦ January 30, 2012

One of the great features of WordPress is the Custom Post Type. It has really opened up WordPress to not only be a great blogging platform – but also a fantastic CMS platform. I am a developer who has been steering full blown sites to WordPress.

Not only does it cut down on time, but it also is something that is constantly updated and upgraded.

Wordpress Changing "Enter Title Here" TextI recently was working on a custom post type for a client website and came across a scenario in which the text “Enter title here” did not make sense for the intended use.  So the question – how do you edit the WordPress “Enter Title Here” text?

The answer really isn’t that difficult. Lets say you were creating a custom post type as a  directory for businesses. Instead of the default text maybe you’d want the text to say “Enter the Business Name”.  It would certainly help eliminate confusion on what “title” is to be used. Read More »»

Page 1 of 6123...5...Last »