I only just discovered that WordPress has a built-in quicktag for identifying excerpts of posts, to be displayed on the homepage (rather than showing the entire post). For many of you this will be old news, but for those of you who aren’t, read on…
The WordPress codex has all the info you need about excerpts – see customizing the Read More for details. In essence, you can use the Excerpt field when authoring a new post, then modify your template to display excerpts rather than full posts.
There is a simpler way, though, via the use of the More quicktag. Simply insert the quicktag after your first paragraph (or wherever you wish the homepage excerpt to end) and it will automatically insert a ‘more’ link at the end of the excerpt, which links you to that point in the actual post. There’s even a button on the WordPress publishing interface to insert the quicktag:
Brilliant. But there’s a catch…
More quicktag and accessibility
Depending on your index.php template, the text of the link which this generates may not be fully accessible. It’s quite probable that it will simply say something like “Read the rest of this entry” after each excerpt – and we all know that this is no good (if you don’t know, imagine a screen-reader user tabbing through your links out of context. They’re not going to know which post each link refers to… “read more of which entry!?”).
The WP codex does address this, but it’s a way down the page. So for your convenience, here’s the solution…
Making it accessible
Simply go to your index.php template and change the code to insert the title of the post.
<?php the_content(“Read the rest of this entry »”); ?>
<?php the_content(“Read the rest of ” . get_the_title(”, ”, false)); ?>
Pretty simple isn’t it!?
See the Pretty Simple blog homepage to see this in action.
PS – the solution isn’t perfect as it doesn’t appear to automatically apply to other pages where you collate posts (such as those generated by tags or from an archive of a previous month). There’s yet another solution – simply add custom text inside the More tag itself. For example, writing a More tag like this <!–more Read more about the More tag –> will produce link text of “Read more about the More tag” in every situation. It will override the insertion of the post title, although the previous solution is a useful back-up if ever we forget to add the custom text to the More tag.
PPS – actually, I may start using the proper ‘excerpt’ function soon – it seems much better for hand-crafting relevant and enticing summaries.
Was this post useful? Did I miss something? Let me know – leave a comment!