Tag Archives: awesome

PHP Site Tweaks

Recently I’ve made a couple of subtle tweaks to my theme to fix minor issues that have bugged me for some time.

1: The Completion of Twitter De-integration
First on my list was to button up the exclusion of my Twitter category.  For some time, I’ve been using the Twitter Tools plugin to create weekly digest posts of all my Twitter activity.  I appreciate this functionality quite a lot.  I like being able to search a subject and find my WordPress blog entries AND tweets on the subject.  However, I didn’t like spamming readers via RSS or pushing down the real content of my site with what I’d consider “archival” content.  Ultimately I wanted to exclude the Twitter category from every possible area except if you actually click on the Twitter header link to get to that category.

Using a couple custom tweaks to my theme’s functions.php file, I was able to mostly implement this back in 2010.  The Twitter category primarily only shows up if you go the category page.  But, recently I also happened to notice that the single posts have links to the previous post and next post; and unfortunately this loop didn’t read the standard WordPress query.  The previous/next post links embrace their own functions completely.  As such, these were showing the posts from my Twitter category.  🙁

With a little research on the functions specific to post navigation, I found it was pretty easy to ditch the Twitter category here as well.

Original code for the previous/next links:
<?php previous_post_link( '%link', '<span>'
. _x( '&larr;', 'Previous post link', 'twentyten' ) . '</span> %title' ); ?>

Updated code for the previous/next links to exclude my Twitter category:
<?php previous_post_link( '%link', '<span>'
. _x( '&larr;', 'Previous post link', 'twentyten' ) . '</span> %title', FALSE, '28'  ); ?>

The FALSE indicates that the next/previous don’t have to be from the same category, and then the ’28’ is the last variable which is “excluded_categories”.

So, the Twitter category now will really only show up if you’re searching or if you’re clicking on the Twitter link in the header nav bar.  I love WordPress.

2: Double Sentence Spacing
Next up is the effect of my typing style that I cannot break.  When I’m done typing a sentence, I hit the spacebar twice.  This is certainly a debated point as to whether single or double sentence spacing is correct – especially on the internet.  It creates “rivers” of white space at times that can be a distraction, and can be a waste of page space and characters in database tables.  Even worse, my theme would display a quirky structure at times by moving that 2nd space onto the leading edge of a new line, hence starting the new line one space indented from the rest of my site.  It looked terrible.

Example of bad spacing, note the clear indent on the 2nd line:
Note the clear space indenting the 2nd line

In my opinion, it’s better to single space.  I just can’t seem to do it.  I can’t manage to break that habit.  So, I scoured the internet for ways to make WordPress do it for me.  It didn’t take long for me to find a simple and easy function to handle this.

function remove_spaces($the_content) {
return preg_replace( '/[\p{Z}\s]{2,}/u', ' ', $the_content );
}
add_filter('the_content', 'remove_spaces');

I added that code to my theme’s custom function.php file (the same place where I exclude the Twitter category), and all is well!  Wordpress adjusts my double spaced content into single space and displays it beautifully:

I love WordPress