Prevent Custom Card URL When Redirection Is Set
This snippet filters the wpex_card_url post meta to return empty if a redirection URL (wpex_post_link) exists. It ensures that custom card URLs are ignored on the front end when a redirect is configured. This way the redirection will take priority as the card URL.
/**
* Filter the custom card URL to empty when a redirection is set.
*
* If a post has a 'wpex_post_link' defined, this snippet ensures that
* 'wpex_card_url' returns an empty string on the front end, preventing
* custom card links from conflicting with redirections.
*/
if ( ! is_admin() ) {
add_filter( 'get_post_metadata', function( $value, $object_id, $meta_key, $single ) {
if ( $meta_key === 'wpex_card_url' && get_post_meta( $object_id, 'wpex_post_link', true ) ) {
return $single ? '' : [ '' ];
}
return $value;
}, 10, 4 );
}
}, 10, 4 );
}
All PHP snippets should be added via child theme's functions.php file or via a plugin.
We recommend Code Snippets (100% Free) or WPCode (sponsored)
We recommend Code Snippets (100% Free) or WPCode (sponsored)
Related Snippets