3 more of my favourite WordPress snippets updated!

Every week I try to sit down and update some of my old WordPress functions, to ensure they meet the latest WordPress coding standards and are in keeping with the best practices. If you ever find a piece of code on thisismyurl (or in any of my plugins) that you feel can be improved, please feel free to fork the code or send me suggestions! In the mean time, here’s what I fixed this week:

Getting WordPress Content Outside the Loop

This function allows you to fetch the_content() without being in a loop.

Generate Tags for Posts without Tags

Tags are useful for a lot more than just SEO, and this little function loops through your posts (25 at a time) to ensure all your posts have tags associated with them. I use it on newspaper websites but it can be used on all WordPress sites well.

Get a quote from a directory

This is an old snippet, and after learning as much as I have I’d likely never code a site like this again but it’s still an interesting concept that can be easily adapted to load images or text for a specific day.

Remember, if you’re not comfortable adding this code to your WordPress theme function.php file, you can also create a site specific plugin for your site.

Two new WordPress plugins for April

This week I’ve added two new plugins to the WordPress repository.

Category Contributors which adds a new Widget to your WordPress website. The Widget lists contributors to the current category while viewing a category page, or contributors to the first category of a post while viewing the post. It’s perfect for newspaper and magazine websites.

Move Posts from the Uncategorized Category is a utility plugin, designed to scan your website for Posts in the Uncategorized category, and move them. It’s based on a post I wrote last week covering how to move posts from your Uncategorized category.

The plugins are now both on the WordPress repository, or you can download them from my list of WordPress plugins.

3 of my most visited tips for WordPress that’s I’ve updated

Sometimes when I’m going through my earlier code samples I want to hit myself, or at the very least go back in time and teach myself how to code WordPress properly. Luckily my blog lets me correct my silly code snippets and turn them into updated, awesome code.

Redirect a post using custom fields

Let’s say you need to redirect a post but don’t know how, this useful tip will let you use a Custom Field to redirect that specific post to any post, without much effort.

How to removed the generator tag in WordPress

By default WordPress inserts a generator meta tag on your page, since some people consider it a security risk I built a small plugin to remove the generator tag as well as a small tutorial on how to remove it manually.

Add an authors picture to your WordPress post

This is one of my older posts, I rewrote most of the code and turned it into a proper WordPress function to all users to display the author image from anywhere in theme file.

If you find a bit of code on thisismyurl.com that needs updating, let me know!

How to remove posted in the uncategorized category of WordPress

Every copy of WordPress comes with a category called Uncategorized which stores all the posts a website writer forgets to categorize. How do you get rid of this category in a quick, efficient manner?

Uncategories Posts How to remove posted in the uncategorized category of WordPress

Fist, we move the uncategorized posts to a new category

Accessing your website admin, create a new category by navigating to Posts > Categories and create a new category by specifying a unique name. Do this until you have new categories to hold all your uncategorized posts.

Now, retrieve a list of all Posts in the uncategorized category by clicking the number of posts displayed to the right of Uncategorized (there are 4 in the example above) and this will show you a list of all posts in that category.

Current Uncategorized Posts How to remove posted in the uncategorized category of WordPress

Screen Options in WordPress How to remove posted in the uncategorized category of WordPressWordPress allows you to bulk edit posts by selecting either all the posts in the current list (the check box beside the word Title) or by selecting the checkbox beside each post you want to affect. You can also adjust the number of posts shown at a time under the Screen Options in the upper right corner of your admin interface.

Next, let’s remove the posts from Uncategorized

Unlike any other category in WordPress, the Uncategorized category can’t be deleted but it can be renamed. Mine for example is called Blog and is the root for all Blog posts on my site. Remember to also update your permalink slug to match the new name.

To remove all the posts you have two choices:

You can manually open each post in the list above and unselect Uncategorized before Updating the post, if you only have a few posts this might not be a bad option.

Or, you can run a script that’ll do the work for you. I’ve written a plugin for WordPress that you can download and install into your WordPress website to do the work for you, or you can add the code to your functions.php file if you prefer.

You can download the plugin from http://thisismyurl.com/wordpress/plugins/move-posts-from-uncategorized-category/

3 WordPress videos from my own WordCamp events

I’ve had the privilege of speaking at several WordCamp events both here in Canada and the US over the past few years, mostly in Toronto and Montreal but also Detroit in 2011. Here’s a collection of three of my WordPress videos from some of those events.

Make a Living by Giving it Away for Free (Toronto)

How to make a living, giving it away for free (Detroit)

WordPress for Newspapers

Are you coming to WordCamp Ottawa?

I’ll be speaking at WordCamp Ottawa on April 27th, let me know if you’ll be there! It’s being held at the University of Ottawa, which is in the downtown of an amazing city.

This year, I’ll be talking about making a living with WordPress. The talk is based on my earlier presentation at the WordCamp Toronto and WordCamp Detroit but it’s been updated significantly since I first gave it. The presentation will focus on my usual themes of sex, money, and power with a real focus on how WordPress can not only pay your mortgage but also empower you to enjoy your career.

Hope you’ll join me in Ottawa!

http://2013.ottawa.wordcamp.org/

How to stop comments from appearing in WordPress

There are a few ways to remove comments from appearing in WordPress, depending on your level of expertise.

Removing comments from WordPress for beginners

Edit CSS in WordPress How to stop comments from appearing in WordPressThe first (and easiest) way to remove comments from your WordPress website is to simply hide them. This means that technically they’ll still be there but nobody will be able to see them.

To do this, simple open your WordPress admin and select Appearance > Edit CSS.

Cascading Style Sheets are what make your website look the way it does. It doesn’t affect how your site acts, only how it looks.

Once you’re in the editor, add this CSS to your website:

#comments {
position: absolute !important;
width: 0px !important;
height: 0px !important;
overflow: hidden !important;
display: none !important;
visibility: hidden !important;
position: absolute !important;
clip: rect(1px 1px 1px 1px); /* IE6, IE7 */
clip: rect(1px, 1px, 1px, 1px);
}

What this does is simply tells web browsers not to display any object on your website contained with the section called comments. As I said, they’re still on the page (if you look at the code) but no longer visible to the public.

More advanced method of removing comments from your theme

The problem with the method above is that it will always remove the comments. That means even if you have comments open on a post, it’ll remove them.

If you want to only hide comments when comments are closed, for example in the TwentyTen theme the phrase “Comments are closed.” will appear when you’re on a Page or Post with comments disabled.

To remove these, you’ll want to open the functions.php file of your theme and add the following code to your site: