Stylehack

Wordpress Tips :: Beating the <!–more–> Tag into Submission

Filed under:

When you don’t want to have long articles displayed in full on multi-post pages, like the index page, Wordpress has a nifty little “tool” you can invoke by inserting a special tag into your post content:

Inserting the <!–more–> tag into the post content in the above image resulted in this display on the index page:

HOWEVER. (There’s always a “however”, isn’t there?!) To my mind there is a problem with the default implementation of this tag… by default when you click on the link to read the rest of the post the content above the tag is hidden!

Why is this a problem? Consider: Your post holds the answer to life’s greatest questions, certainly worthy of being printed! However, using the <!–more–> link, your reader will have to print both the index page AND the content following the <!–more–> tag separately… or be wise enough in WordPress blog-ways to go back to the index page and use the article title link instead of the <!–more–> tag link to print your post.

Besides, I just think it looks stupid to go to a page missing the leading paragraph(s) and title info for the post. Color me picky. “-)

The Quick and Easy Fix

Editing your theme files using your favorite method, open index.php and locate the line calling the php function the_content

<?php the_content('Read the rest of this entry &raquo;'); ?>

to this:

<?php the_content('Read the rest of this entry &raquo;', FALSE); ?>

Note: If that doesn’t work for you, then try this version:

<?php the_content('Read the rest of this entry &raquo;', FALSE, ''); ?>

Voila! All fixed. The “FALSE” tells WordPress to display the leading (also called “excerpted”) content when loading the article after using the ‘Read the rest of this entry »’ link.

IMPORTANT:   The code above is from the default WordPress 2.5.1 index page. If you are using a custom theme, it may use other words than ‘Read the rest of this entry »’ and it may have a style declared, image called, etc. So you may have to look around. In a poorly designed blog theme, you may even have to add it yourself. Gasp! Use the default theme as a guide in this instance.

Please keep in mind that this string of code may be in other files and will need correcting in those files also, depending on your theme! The process that uses the <!–more–> tag can be called and implemented on any page that lists more than one post. So perhaps a custom category listing page may use it, or an archive page. Like I said, you will have to look around if it doesn’t work somewhere after you’ve put the <!–more–> tag into your post content.

Customizing the Link String

A final quick word on making the <!–more–> tag your own: You can change the words to suit your purpose! Simply replace the string as shown below:

<?php the_content('Read the rest of this entry &raquo;', FALSE); ?>

becomes

<?php the_content('Don't stop now!  Read on...', FALSE); ?>

More on Customizing the <–more–> Tag

For more information on what you can do with this tag, please check out the information on the WordPress codex.

http://codex.wordpress.org/Template_Tags/the_content

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Stylehack © 2008 - Becky Peters :: All Rights Reserved
Powered by WordPress