Categories
Main

Hacking WordPress – Link In The Title (update 2)

As I have just figured out after some of the upgrades the external link in the title hack was, indeed, broken. In fact, I am somewhat puzzled, as it worked on some of my installations and didn’t work on others.

It turns out that the method of obtaining the permalink for the post is returning the canonical URI no matter what permalink system has been set up (I use custom on this blog). For example, even if you have something SEO-friendly, the code

$permĀ  = $post_id->guid;

would still return https://www.istudioweb.com/?p=427 as a link to this post. The right way of doing it now (before WP 2.7 arrives) is change the above line to:

$permĀ  = get_permalink($post_id);

That’s it. Should work.

P.S. Updated the downloadable txt file. Click here to view.

Categories
Main

Hacking WordPress theme – External URL in title still works

At least once a week I get an e-mail about the WP theme hack I posted in January. Most of the people ask how to make the hack work in WP 2.5 and 2.6.

Here’s the simple answer – if you didn’t touch your theme (I didn’t) and if you have just upgraded the WordPress installation itself – then the hack should still work. The original post with instructions is here.

The proof is this post – look at the title and take note that link in the title leads to the main blog page, not to the post itself.

If something actually did went wrong, check the following:

  1. Your theme’s functions.php file or whatever the name of the file with theme’s functions is. It should still contain the code from the original post.
  2. Your theme’s index.php file or whatever the main index template file name is. It should have the original hack as outlined in the original post.
  3. Custom field – the new URL must be in the value field, whereas the custom field name should be url1 or whatever you made it to be.

Let me know if the damn thing is acting up again.

Categories
blog

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.