Category: SDAC Blog

Upgrade Google Analytic Tracker Code

If you use Google Analytics on your web site, you should update your tracker code that is placed in your code. The new tracker is faster, and offers added tracking functionality (See Google’s announcement)

New Code: (put your tracker ID in where you see the X’s)



var pageTracker=_gat._getTracker('UA-XXXXXX-X');
pageTracker._initData();
pageTracker._trackPageview();

While you are updating your code, you might also want to consider moving this and any other javascript to the bottom of your web site for improved performance.

Exclude Single Post in WordPress

If you would like to exclude one post from your blog, archive, search results or wherever you need to on your blog, you can do so by putting in a small piece of code within the particular WordPress loop:

The following example will show all posts except for the post with the ID of 179:

<?php if ( $post->ID == '179' ) continue;?>

This is something that I get a lot of requests for and is very useful in a number of situations.

Exclude Single Category in WordPress

If you ever need to exclude a single category from a WordPress page (archives, index, category page, etc) you can easily do so by using a little conditional tag code within the WordPress loop.

The example below will skip over any post that is in the category with the ID of 35:





This can be helpful if you want to not show a particular category in your blog (if you have a category based site setup) – or if you want to hide some categories from your search results.

Remove “Private:” From WordPress Titles

I needed to be able filter out the text “Private:” for posts and pages that were password protected but did not want to edit any core WordPress files. To filter out that text, I added the following code into my functions.php file (within my theme directory):

function remove_private_prefix($title) {
$title = str_replace(
'Private:',
'',
$title);
return $title;
}
add_filter('the_title','remove_private_prefix');

(I also posted this filter in the WordPress Support Forum)

SDAC Recommends: WP Plugin: WP Super Cache

There is a new (relatively) caching plugin in town for WordPress called WP Super Cache and after using it now for a few version, I have to say I would recommend this over the old standard WP-Cache plugin. The plugin is easy to install, easy to configure, and will produce a noticeable load time decrease for your WordPress sites. There are also options to set if you want to “digg-proof” your site, use compression, or “lock down” your site during an expected traffic spike.

WordPress Logic: If Is Logged In

There are several tidbits of code that I have collected over the past few years that make it easier and easier to turn a simple WordPress installation into a very functional content management system (CMS). There are many times when it would be nice to show logged in members certain bits of information (certain categories, posts, or just a simple “Welcome back!”) and of course there is a simple way of doing this:

<?php if ( is_user_logged_in() ) echo 'Welcome back!';?>

That bit of code will allow you to do something like this which will allow you to show the logged in user’s preferred user name (selected in the User preferences), and then a list of member only pages (private page parent is page ID 20 – I am showing all sub pages of the members-only pages marked as private). If the user is not logged in, they will get a Welcome visitor! greeting :

<?php
if ( is_user_logged_in() ) :
  global $current_user;
  get_currentuserinfo();
?>	
  <p>Welcome back <?php echo esc_html( $current_user->display_name );?></p>
  <p>Here is a list of private pages only viewable by Members:</p>
  <ul>
  <?php wp_list_pages('post_status=publish,private&child_of=20');?>		
  </ul>
<?php else : ?>
  <p>Welcome, visitor!</p>
<?php endif;?>

You can make it as simple as a change in greeting for members and non-members, or put in specific logic like I did with showing the pages. The potential is limitless.

WordPress Update: 2.3.2

WordPress 2.3.2 has officially been released. The new version includes bug fixes and an urgent security fix. For more information on WordPress version 2.3.2, read the official WordPress version 2.3.2 documentation.
Download the latest versions of WordPress: WordPress 2.3.2

WordPress Plugin Update: Akismet

Today Automattic released an update to the Akismet. This is a great plugin to help with comment spam and has been priceless on all the sites I manage. If you are not using this plugin, you can use it for free for personal sites, or pay $500 for commercial sites. Check it out!

SDAC Recommends: WP Plugin: Top Level Categories

If you have ever wondered how to clean up WordPress URLs by removing the /category/ from your URLs, check out the plugin: Top Level Categories. After you activate it, you can access your web pages that were once only reachable by: /category/web-design/ by now using just /web-design/.