-
-
Save JoeSz/01ec83dbcac8e343342b5168e83da690 to your computer and use it in GitHub Desktop.
WordPress: Redirect single custom post type to archive page.
This file contains 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
// redirect single posts to the archive page, scrolled to the current member. | |
// * this is for a post type of "board_member" | |
add_action( 'template_redirect', function() { | |
if ( is_singular('board_member') ) { | |
// I used the two variables to put the member's name as the ID of the article | |
// so the redirect would automatically scroll. This can be removed. | |
$title = get_the_title(); | |
$url_append = str_replace( ' ', '-', strtolower($title) ); | |
global $post; | |
$redirectLink = get_post_type_archive_link( 'board_member' ) . "#" . $url_append; | |
wp_redirect( $redirectLink, 302 ); | |
exit; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment