Hacking WordPress theme – external URL for post title
Sometimes something weird happens – I demand something that isn’t available. With software it’s easy (that’s how I got into computers), you dig in the code and you tweak and hack around until it does what you want.
When I just started this blog on Blogger quite a while ago, there was this feature that allowed to set up a link for your title – in case if you don’t want the title of the post to link to external resource. Why would you do it – whole another story, but it was just possible. With WordPress, even matured to version 2.3, it is still not.
I have decided to dig in and figure out how to do it with as least effort as possible. I have no idea how to build a WordPress plugin yet and I didn’t really have time to figure that out. So I decided to go hacking. Through various resources on the web I figured what needed to be hacked and how. Initial idea was to leave core files untouched and hack the theme only, so any time you upgrade your WordPress installation the feature remained untouched.
The only two places you will need to touch are functions.php and main index file of your template. This is such an easy process that almost any can do it in under 15 minutes.
In your WP admin open the Presentation -> Theme Editor screen and click on functions.php – you should see something like the following screen:
Open the attached hack file and copy everything from it into functions.php, then click Update File. When done, click on Main Index Template or on index.php – you should see something similar to the following screen:
Replace the line that says
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
with the following:
<?php print_post_title() ?>
Now, whenever you feel like let your post title leave your blog and point someplace else, just scroll down in your post writing screen, create or select a custom key named url1 or title_url or url_title and put that external URL in value box.
UPDATE: This still works for WP 2.5 and WP 2.6, read more in the update.