Quicktag Modification

March 23rd, 2005

While I haven’t done a lot of modification to the default WordPress 1.5 install, there are a few things I’ve changed that I rather enjoy.

After looking at a Rambling Thought, I figured a way to make the “more” Quicktag even better. I left a comment about this on Neerav’s site; I can only assume that it’s awaiting moderation right now.

All Your the_content Are Belong To Us!
I have my own sense of style and like to make things uniquely my own. Almost immediately, upon even discovering that the “more” Quicktag does what I want it to, I wanted to change the way it displayed things. The first thing I wanted to do was make the post title in my “more” link bold and surrounded in quotation marks (it’s the title of the page and, therefore, should be punctuated as such; the bold formatting is just to make the title stand out a bit). It’s really easy and requires changing only one file. In my index.php page, I’ve found:


By digging deeper into that function (found in template-functions-post.php), I saw that there are so many things that can go inside those parentheses to make my life much easier. I’ll explain why I did it afterward, but here’s what I ended up with when I was finished:

the_content("Read more of" . the_title('"<strong>','</strong>"',false), 1);

So, with the_content function, the first phrase inside the first set of parentheses is what will display when there is a “more” link. It’s “Read more of” in my case. the_title is, of course, the title of the post being linked to. So far, this newly applied function call will spit out:
Read more of The Next Post
if I ever click on the “more” Quicktag.

Inside the second set of parentheses, between the single quotation marks, is what will appear in front of the_title. Naturally, the second set of single quotation marks is what will appear after the_title. I have an opening quotation mark and STRONG tag set to display before the_title and a closing STRONG tag and quotation mark set to display after the_title. So, the finished output of the above code is this:
Read more of “The Next Post

Now that I’d formatted the visible text, I wanted to change what the “more” Quicktag did to my code, too, the invisible text to most users. The “more” Quicktag inserts a bookmark link into the full-post page. It seemed odd to me to click on Read more of “The Next Post” and find myself somewhere other than the top of the page. I just had to stop the bookmarking! The fate of the worl– well, I just didn’t want it there.

Get The # Out!
I opened template-functions-post.php and searched for get_the_content. Near the end of that function is a– Wait! A quick search for “#” and I found it! There are only two #s in template-functions-post.php, so my first search took me where I needed to be. Here’s what I found:
$output .= ' <a href="'. get_permalink() . "#more-$id">$more_link_text</a>";

In order to make my “more” link a link to the full-post page (and not to a bookmark within that page), I replaced the above with this:
$output .= ' <a href="'. get_permalink() . "">$more_link_text</a>";

Removing the pesky “#more-$id” bit of code turned my “more” link into a simple, honest, direct link to the full-post page. None of this bookmark garbage.

I wasn’t satisfied with disabling the link to that bookmark; I didn’t want that bookmark inserted in the full-length post at all. That meant I had to make one more modification, but it wasn’t too difficult, either.

Exorcising the Code
It was now time to remove the ghosts of Quicktags past. Just above the spot I previously modified (we’re still in template-functions-post.php) is the following:
$output .= '<a id="more-'.$id.'"></a>'.$content[1];
Since I don’t need that bookmark at all, I got rid of the link tag and just keep the declaration to display the actual content. Here’s what I ended up with:
$output .= $content[1];

The Result…
A quick trip to my home page will show you how this turned out. And if anyone comments with a simpler way to do all this, I will personally come and TP your house for a week straight. This didn’t take me too long to do, but I would hate to have made these changes and written this article, only to find out that “Oh! You could have…” was much easier. I’m sure it’ll happen, though, so I’ll go to Costco to buy some toilet paper.

Have your say...

Comment Preview: