Create custom links for excerpts with php dynamically

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…

<?php 
   $url = get_post_meta(get_the_ID(),'Excerpt URL',true); 
   if ( ! empty($url) ) {
      echo "<a href="https://wordpress.stackexchange.com/questions/88116/{$url}">Read more...</a>";
   }
?>