Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function labnol_blogger_query_vars_filter( $vars ) {
- $vars[] = "blogger";
- return $vars;
- }
- add_filter('query_vars', 'labnol_blogger_query_vars_filter');
- function labnol_blogger_template_redirect() {
- global $wp_query;
- $blogger = $wp_query->query_vars['blogger'];
- if ( isset ( $blogger ) ) {
- wp_redirect( labnol_get_wordpress_url ( $blogger ) , 301 );
- exit;
- }
- }
- add_action( 'template_redirect', 'labnol_blogger_template_redirect' );
- function labnol_get_wordpress_url($blogger) {
- if ( preg_match('@^(?:https?://)?([^/]+)(.*)@i', $blogger, $url_parts) ) {
- $query = new WP_Query (
- array ( "meta_key" => "blogger_permalink", "meta_value" => $url_parts[2] ) );
- if ($query->have_posts()) {
- $query->the_post();
- $url = get_permalink();
- }
- wp_reset_postdata();
- }
- return $url ? $url : home_url();
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement