Post Click Redirect to Custom URL instead of Single Post Page

admin2025-01-08  3

I have a custom post type called "articles". When an article link is clicked, I want to redirect them to custom URL(this URL is saved in the database as custom field) instead of the single page. How can I do it? I couldn't find an action hook/filter for it?

I have a custom post type called "articles". When an article link is clicked, I want to redirect them to custom URL(this URL is saved in the database as custom field) instead of the single page. How can I do it? I couldn't find an action hook/filter for it?

Share Improve this question asked Nov 29, 2019 at 4:23 I am the Most Stupid PersonI am the Most Stupid Person 5681 gold badge7 silver badges30 bronze badges 2
  • Are you in control of the templates? You could just replace the permalink function with the custom field. – Jacob Peattie Commented Nov 29, 2019 at 4:57
  • @JacobPeattie No. I want to do this whole site. Archive pages, widgets, etc. Everywhere.... So this won't work and I don't like touch theme & plugin files for this purpose. – I am the Most Stupid Person Commented Nov 29, 2019 at 6:19
Add a comment  | 

1 Answer 1

Reset to default 0

For redirect to custom url you need to change post detail link to custom url. You simply remove post link and apply custom url.

<a href="<?php echo get_field('link'); ?>"><?php the_title(); ?></a>

In my case "link" is custom url.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736267891a1230.html

最新回复(0)