Making WordPress.org


Ignore:
Timestamp:
08/03/2021 04:47:26 AM (3 years ago)
Author:
dd32
Message:

Theme Directory: Redirect 404's that are to theme urls like /$theme/junk/input/here/ to /$theme/.

Fixes a number of bad incoming links according to Google Search Console.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-themes/functions.php

    r11165 r11166  
    6767        wp_safe_redirect( home_url( '/search/' . urlencode( get_query_var( 's' ) ) . '/' ), 301 );
    6868        die();
     69    }
     70
     71    // Handle 404 pages where it's a singular theme followed by junk, for example, /themes/twentyten/junk/input/
     72    if ( is_404() ) {
     73        $path = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
     74        if ( preg_match( '!^/themes/([^/]+)/.+!i', $path, $m ) ) {
     75            $posts = get_posts( [
     76                'name'        => $m[1],
     77                'post_type'   => 'repopackage',
     78                'post_status' => 'publish'
     79            ] );
     80
     81            if ( $posts ) {
     82                wp_safe_redirect( get_permalink( $posts[0] ), 301 );
     83                die();
     84            }
     85        }
    6986    }
    7087
Note: See TracChangeset for help on using the changeset viewer.