Archive

Archive for the ‘Make Wordpress Do What You Want’ Category

Generate Link to Wordpress Home Page with the bloginfo Function

August 18th, 2009 No comments

Problem

Most Wordpress developers will develop their theme locally and then move it to a production server once it’s ready to launch the site. A problem can arise when you want to generate links to your blogs homepage on the dev site and then when you move to the production server, your links all break. Also, if you move your blog into another directory or subdomain for some reason, your links can also break.

Solution

Rather than hard coding your home page url into your theme pages, you can use the bloginfo() function to instead load the blog url that you entered into the Wordpress Admin section, that way you’ll always load the correct link.

The wordpress url is where you installed wordpress to on your server

The wordpress url is where you installed wordpress to on your server

So wherever you want to load your blog’s home page url, instead of hard coding the url, use this piece of PHP code:

<?php bloginfo('url'); ?>

This should hopefully help prevent some headaches when developing a theme that will eventually be located at different domains.

Automatically Display Related Posts on Your Wordpress Blog

July 20th, 2009 No comments

Problem

There are two really important reasons why you want to add a list of links to related posts on your Wordpress blog for each post you right. The first is that this is a really useful thing for your readers. Most likely, unless the people reading your blog are subscribed to it or are reading it because they know you, your users reached your blog through the search engines. If that’s the case, after having read what they came to your blog looking for, having a list of other relevant posts can greatly increase the chances of them staying around and enjoying your other posts. This will increase your readership and potentially convert these new visitors into subscribers.

The other reason to add related post links is because interlinking pages on your site is a big deal for SEO and properly doing so can greatly increase the chances for the search engine spiders to successfully crawl your site. If you’re looking to crow your traffic organically, that’s obviously a really big deal.

Now, having to manually add a list of links to the bottoms of your posts is tedious and pretty dumb. So how do you do it automatically?

Solution

yarpp-relatedness-screenshot

Click to Enlarge

The plugin that solves this problem is hands down one of the smartest plugins I’ve ever used. Download Yet Another Related Posts Plugin and active it. The way this plugin works is it calculates a “match score” for each pair of posts on your blog and caches those results. It does this by considering all of the relevant parts of a post in a special algorithm that decides how similar two posts are. You are able to decide exactly what options are considered when the program calculates related posts.

Then, after you write a new post and view it on your site, the plugin will display the 3 most relevant related posts on your site as links after the body of your post. Over time, the algorithm will get smarter and smarter as it has more and more content to work with.

Click to Enlarge

Click to Enlarge

The one caveat for this plugin is that you won’t see super accurate results until you have written a good amount. Initially, the plugin will either say that it hasn’t found any similar posts or that it has only found 1 or 2. You can mess with the “Match Threshold” in the settings to get better results, or if you just wait a little while you will begin to see better results as the amount of content on your site increases.

 

Automatically Generate and Submit an XML Sitemap with Every Wordpress Post

July 19th, 2009 2 comments

Problem

All of the major search engines now use XML sitemaps as a way to have a reliable map of your whole site when it comes time for them to crawl it. This is a key thing to have in your root directory as it nearly guarantees that your whole site will be crawled next time the spider hits your site. Without the sitemap, there’s a potential that some of your pages can get missed.

Also, by submitting your sitemap after adding new content, you can help speed up the spidering process for that new content, helping it reach the search engine result pages even faster.

But when it comes to generating and submitting your XML sitemaps, the situation kind of sucks. Especially if you find yourself posting a few times a day on your blog, you’ll quickly give up on doing all of the manual work to get your sitemap sent out across the internet for the search engines to use.

Solution

Click to Enlarge

Click to Enlarge

The way to solve this manual work problem is to download and install the plugin Google XML Sitemaps. What this plugin allows you to do is configure which search engines you want to submit to, how frequently, and how you want the XML Sitemap to be built, and then it will automatically take care of all of the manual work of getting everything generated and submitted for you.

Once this plugin is installed and configured, you can be sure to have your site being constantly monitored by the search engines as you add more and more content. This plugin is essential for anyone looking to increase their SEO rankings through the major engines.

 

Disabling Automatic Post and Page Formatting in Wordpress Themes

July 16th, 2009 2 comments

Problem

Sometimes when working on Wordpress powered sites, especially those that require a lot of custom HTML/CSS formatting through the HTML tab of the editing page, you’ll run into instances where the automatic formatting Wordpress uses becomes really annoying. Wordpress runs a filter on the content of your pages and posts that automatically adds in paragraphs where you might not want them sometimes.

Obviously if you’re sticking to writing relatively simple posts without too much formatting, this isn’t a big deal. But if you using a lot of custom CSS styles in your pages to style pages in a more radical way without having to mess with template files, you’ll need a solution that allows you to bypass that automatic formatting.

Solution

There are a few ways to filter your automatic formatting in Wordpress but the following is the best. You need to add a bit of code directly in front of the call to “the_content()” that disables the filtering. So instead of calling the_content like you normally do in a theme page:

<?php the_content(); ?>

…you would add a single filter directly in front of that comment, like so:

<?php remove_filter ('the_content', 'wpautop'); ?> 
<?php the_content(); ?>

That will disable the formatting of the body of your page. Be careful with using this filter tag, as all of the clean formatting that Wordpress normally applies will disappear when you use it. Your best bet is to create a copy of whatever template page you want this to be applied to and rename it so you can select it as a custom template when writing your new page.

How to Exclude Pages from Your Wordpress Navigation Menu

July 16th, 2009 1 comment

Problem

Oftentimes when building out a CMS style Wordpress site, you’ll run into instances where you’ve added pages to your site that you don’t want to show up in the main navigation. This is especially true if you’re utilizing a drop down menu navigation system that can access your multi-level pages.

There are two ways to go about hiding these pages from your navigation menu. The 1st is to manually edit your menu code (most likely in your header.php file) to exclude individual pages by hand. While this work, it’s A) Clunky as hell and B) prone to breaking if a page is deleted and another one added, for instance.

Solution

exclude-page-screenshotDownload and install a plugin called “Exclude Pages From Navigation“. What this plugin does is add a small context menu on the right sidebar of your edit and add new pages (seen on the right) that allows you to check off whether you want that page to show up in the automatically generated Wordpress menus.

By unchecking that box, you hide your page from showing up, allowing you to use that page for whatever you like without having to worry about people stumbling upon it through your menu system.

Fixing 404 Error When Using Wordpress Pretty Permalinks with WAMP

July 13th, 2009 2 comments

Problem

When you’re developing locally for a client, you want to try and replicate the server environment as closely as possible. That’s why using tools like WAMP are so great because they provide you with a pretty much stock version of a typical server setup that will work for 99% of use cases when it comes to developing and deploying a Wordpress site. But sometimes, things break. And when they break, they don’t make sense.

A perfect example is using a default install of WAMP and trying to setup “Pretty Permalinks” with Wordpress. An example of pretty permalinks is setting your permalinks to /%postname%/ instead of the standard www.domain.com/p?=23. Obviously a favorable setup for SEO and usability.

But if you were to set the permalinks to that with a default WAMP install, your site will start throwing up 404 pages for all pages that are linked to with the new permalinks. The problem is that mod_rewrite is not turned on by default with WAMP, so Apache is incapable of rewriting URLs according to .htaccess rules that Wordpress sets when you modify your permalinks.

Solution

rewrite-module-screenshot

Click to Enlarge

In your taskbar in the bottom right of the screen in windows, left click the WAMP icon, go to Apache, then Apache Modules, then make sure that “rewrite_module” is checked. Checking that will automatically restart WAMP and will activate mod_rewrite, allowing you to modify your permalinks however you want while not breaking anything!

Introducing ‘Make Wordpress Do What You Want’

July 13th, 2009 No comments

So in both my own personal projects as well as projects I’ve been working on with other people, I’ve gotten to know Wordpress pretty well. It’s a surprisingly powerful platform, and while it does have its shortcomings (like sidebar management), it can be transformed into a pretty powerful CMS platform if the right tweaks are applied. So lately I’ve started keeping track of all of the different little “off the beaten path” tricks that I use somewhat frequently on Wordpress setups, especially on sites that are meant more as CMS sites than typical blogs.

Some of the tricks might seem brain dead simple and leave you wondering “Why are you showing me this?” while others I hope are things you might never have heard of. But the purpose of this series is to simple build up a pretty complete set of tips and tricks that someone using Wordpress as a CMS can reference when working on their own projects.

I’ll try and go into a little bit of explanation for each trick for both why you would use it as well as why it works the way it does. That way, you’re not just copying and pasting code into your site, you’re actually learning from what is going on. So tomorrow is the day I’m planning on kicking off this series. I have a good amount of tricks saved up so far so I’m going to try and post every other day or so to get this series full of all of the good stuff.