Last active
May 11, 2023 12:57
-
-
Save aguilar1181/862af5b42a5d2d52d8f0ff662dde74f0 to your computer and use it in GitHub Desktop.
Redirect a post format link to a ACF custom field
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Add redirect to post format links. | |
* | |
*/ | |
function umg_link_format_redirect( $original_template ) { | |
if ( 'link' === get_post_format() ) { | |
//get post meta | |
global $post; | |
//create redirection using ACF field from post with ID. | |
//default status is 302, you can add 301 as a second argument | |
wp_redirect( get_field( 'link_redirect', $post->ID ) ); | |
//exit redirect since WP does not do it automatically | |
exit; | |
} else { | |
return $original_template; | |
} | |
} | |
add_action( 'template_include', 'umg_link_format_redirect' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment