1

is it possible for the "Read More" buttons in front page which normally leads to the post , to change it to lead to an external webpage. So one can lead to post and the other can lead to external webpage

2 Answers 2

0

Yes, you can use the Read More filter: https://codex.wordpress.org/Customizing_the_Read_More#Modify_The_Read_More_Link_Text

Per the discussion below, in this case, there's a plugin called Page Links To that may solve your problem. You would create a post in WP but set its permalink to the external URL you want to link to, so it would appear on the front page but its read more button would go to the external URL for just that post (or however many others you created this way).

7
  • yes but this changes all the Read More buttons not only one. Right? Mar 29, 2017 at 20:19
  • @AggelosSunDanceTroulakis within the func you hook to the_content_more_link you can access the global $post to decide what URL you want to link to. Mar 29, 2017 at 20:21
  • If you only want to change the front page (not other locations where Read More may appear, like categories and other archives), you could edit front-page.php directly with a custom loop.
    – WebElaine
    Mar 29, 2017 at 20:23
  • I mean in the front page I have 3 "Read more" buttons for 3 different posts. I need only one of them to point to external page Mar 29, 2017 at 20:28
  • 1
    For completeness sake, the way in which you'd actually accomplish this using a the_content_more_link filter would be to use a custom field (post metadata) to set the external link. In the filter, check for the existence of that meta-data, and if it exists return anchor markup containing the meta-value (the external URL) - if the post doesn't have the meta-data, return the argument passed into the filter as-is. This leaves permalinks untouched, however - you should additionally use a pre_get_posts hook to wp_redirect() queries for single posts with the meta-data to the external URL.
    – bosco
    Mar 29, 2017 at 22:13
0

Other solution is put custom meta field, for example Advanced custom field, create text or link field, then you can output read more link in your template, loop or singe like this:

<?php if (get_field('custom_link')): ?>
    <a href="<?php the_field('custom_link'); ?>" target="_blank">Read more</a>
<?php else: ?>
    <a href="<?php the_permalink(); ?>">Read more</a>
<?php endif; ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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