the_content (more_link_text)

Mon, 5 Sep 2005

Warning: WordPress rant coming.

How in the bloody effing heck am I supposed to generate valid code with the more_text_link argument to the the_content template tag?

What I had been doing was this:


the_content ('<div class="morelink"><p>Continue reading ' . the_title ('<q>', '</q>', FALSE) . '</p></div>');

However, that gave me output HTML like this:


<a href="http://blog.niceperson.org/2005/09/04/heather-park-revisited/#more-441">
<div class="morelink"><p> Continue reading <q>Heather Park revisited</q> </p></div> </a>

That’s well-formed code, but it’s certainly not valid, and I didn’t intend to let that go for long. Unfortunately, there’s no way to enter before or after text in the the_content template tag, and any way I tried to insert block elements around the more-link just screwed it up worse. You see, just inserting the block-level elements in the entry doesn’t work, because you also have to close the blocks after the more-link, and everything after the link is chopped off. You see? There’s no way around it.

I can only imagine one way to generate valid markup with that tag, and that’s to use the WordPress feature of closing open tags in order to make markup validate. I refuse to use that feature because I want full control over my own markup. I hate programs that think they’re smarter than I am. (The exception to that, of course, is if I wrote the software myself and know the end cases where it falls down. In that case it’s my own fault.)

So what did I do? I hacked WordPress and tacked before and after arguments onto the_content. If you’re interested, here’s a patch. It works for me on WordPress 1.5.2, and it probably has a fair likelihood of working on other versions too (depending on how much the the_content function has or will be modified), but I make no guarantees. Make a backup of the original template-functions-post.php file before you apply my patch. If you have no idea what I’m talking about with patches and the like, you’re probably better off not modifying your code.

I’ll also see what I can do about raising this issue with the WordPress developers and possibly getting my changes, or something like them, folded into the main WordPress code.

Post a comment











XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

OpenID: If you use OpenID, your comment will be approved automatically and will not be held for moderation.