WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Good Day

I am using excerpts in my wordpress theme. Now in wordpress's documentation, they say wordpress does not automatically add links for the excerpts, you have to manually add them like this:

Original excerpts file

 <div class="content">
 <?php the_excerpt(); ?>

Adding links

<div class="content">
<?php the_excerpt(); ?>
<a href="<?php echo get_permalink(); ?>"> Read More...</a>

Now what I would like to do is to link each excerpt to a different wordpress page, and not to its own excerpt. So for that, I would have to create a custom php function to create a unique link for each excerpt, pointing to a different page each. How do I do that?

See my website where the excerpts are located - It is right below the main slider named: Pastor's Corner, Mother's Heart, Sermons etc...

Thank you

share|improve this question
You know how to create URLs so just point the link to wherever you want. There isn't enough detail in your question for anyone to write the code for you. "a different page" is pretty generic. – s_ha_dum Feb 23 '13 at 23:47

For something like that, you need to use custom post metadata (aka "Custom Fields").

There are two steps:

  1. Define a new custom field for the post (this will be where you enter your URL)
  2. Output that custom field in your template.

STEP 1 First, you will need to define a new custom field to store your links. Start by editing any post you want to do this with. On the edit screen, find the "Custom Fields" box. If it's not visible, open the "Screen Options" tab (at the top-right of the window), and make sure the "Custom Fields" option is checked.

Now, define a new field. Click on "Enter New" and type a name in the left box... for example, you might call this "Excerpt URL". In the next field, type the URL you want to link to.

Sidenote: From now on, you will be able to select "Excerpt URL" from the Custom Fields drop-down any time you want to use it with a post. No need to type it every time.

STEP 2 Now, you just have to output that post meta from your template file. You want to use WordPress's built-in get_post_meta() function. Use it within the loop like so...

   $url = get_post_meta(get_the_ID(),'Excerpt URL',true); 
   if ( ! empty($url) ) {
      echo "<a href='{$url}'>Read more...</a>";
share|improve this answer
Thank you Matt. This sounds like it can work, but there is one problem. The excerpt posts do not have any custom field values - So I cannot link the excerpt to a page...Or is it the other way around? Do I link the page, with a custom field, to an excerpt? But how would you be redirected to the page when clicking on the excerpts 'Read More' link? What I want to do: Excerpt>Read more link>Link to a page. Now this is easy to use normal html and just write out each excerpt linking to each page, but how do I do this dymanically? With one html definer/parent? – DextrousDave Feb 24 '13 at 10:53
Featured Image, Excerpt and slug are the only screen options available for the exerpts... – DextrousDave Feb 24 '13 at 10:54

The excerpt automatically redirects to the single post page when clicked. I think the trouble you are having is is that [...] is not clickable, and you want to make it clickable. To do this you need to replace [...] with a custom Read More... link.

You need to do something like this:

function new_excerpt_more( $more ) {
    return ' <a class="read-more" href="'. get_permalink( get_the_ID() ) . '">' . __('Read More', 'your-text-domain') . '</a>';
add_filter( 'excerpt_more', 'new_excerpt_more' );

If you need a custom excerpt that does not strip html tags, go and check my answer on a previous question here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.