Post Pic

Create custom “Read more” links on your WordPress blog

The “more” link is indeed a great WordPress capability, which allow you to choose the part of the post to be displayed on the homepage. Then, a “Read more” link is displayed. But how can you change the text of this link? Just read on.

To achieve this recipe, the first step is to edit your posts and create custom fields. Give them custom_more as a key, and the text to display as a value.

Once done, edit your index.php file (As well as category.php, search.php, etc) and find a line similar to this:

the_content("Read more");

Simply replace it with this code:

<?php $custommore = get_post_meta($post->ID, 'custom_more', true); ?>
<?php if (!$custommore) { $custommore = 'Read More &raquo;'; } ?>
<?php the_content($custommore); ?>

That's all. Now, if you create a custom field named custom_more, its value will be displayed instead of the classic "Read more" link.

Thanks to Chris Cagle for this very usefull trick!

9 Responses

Jun 19 2009 09:40

Nice, but the trick I like best is that you can add text to the {!–more–}-tag to get whatever ‘read more’-message you want.

{!–more read 1,000 words more–}
{!–more not a whole lot more–} etc.

[Where { is used, use <]

Jun 19 2009 12:31

can it be done without custom field?

Jun 19 2009 12:36

Nice tip. Thanks a lot.

Jun 19 2009 17:45

As IJsbrand is stating in the first comment all of this is built in in Wordpress already. No need for custom fields at all.

Jun 20 2009 08:26

Nice tip! Been looking for something like this..

Jun 21 2009 23:09

2sms:
just replace
the_content(“Read more”);
“Read more” with whatever you want.

Jun 29 2009 00:31

Thank you for this recipe! It worked like a charm and was EXACTLY what I needed!

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required