Last active
December 21, 2017 10:53
-
-
Save takien/21a9209fe867f8d5fe4d58a62a0cb79d to your computer and use it in GitHub Desktop.
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 | |
function custom_rewrite_rule() { | |
$cat_base = ltrim(get_option('category_base'),'/').'/'; | |
$rewrites = Array( | |
$cat_base.'(.+?)/[^/]+/attachment/([^/]+)/?$'=>'index.php?attachment=$matches[1]', | |
$cat_base.'(.+?)/[^/]+/attachment/([^/]+)/trackback/?$'=>'index.php?attachment=$matches[1]&tb=1', | |
$cat_base.'(.+?)/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$'=>'index.php?attachment=$matches[1]&feed=$matches[2]', | |
$cat_base.'(.+?)/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$'=>'index.php?attachment=$matches[1]&feed=$matches[2]', | |
$cat_base.'(.+?)/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$'=>'index.php?attachment=$matches[1]&cpage=$matches[2]', | |
$cat_base.'(.+?)/[^/]+/attachment/([^/]+)/embed/?$'=>'index.php?attachment=$matches[1]&embed=true', | |
$cat_base.'(.+?)/([^/]+)/embed/?$'=>'index.php?name=$matches[1]&embed=true', | |
$cat_base.'(.+?)/([^/]+)/trackback/?$'=>'index.php?name=$matches[1]&tb=1', | |
$cat_base.'(.+?)/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$'=>'index.php?name=$matches[1]&feed=$matches[2]', | |
$cat_base.'(.+?)/([^/]+)/(feed|rdf|rss|rss2|atom)/?$'=>'index.php?name=$matches[1]&feed=$matches[2]', | |
$cat_base.'(.+?)/([^/]+)/page/?([0-9]{1,})/?$'=>'index.php?name=$matches[1]&paged=$matches[2]', | |
$cat_base.'(.+?)/([^/]+)/comment-page-([0-9]{1,})/?$'=>'index.php?name=$matches[1]&cpage=$matches[2]', | |
$cat_base.'(.+?)/([^/]+)(?:/([0-9]+))?/?$'=>'index.php?name=$matches[1]&page=$matches[2]', | |
$cat_base.'(.+?)/[^/]+/([^/]+)/?$'=>'index.php?attachment=$matches[1]', | |
$cat_base.'(.+?)/[^/]+/([^/]+)/trackback/?$'=>'index.php?attachment=$matches[1]&tb=1', | |
$cat_base.'(.+?)/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$'=>'index.php?attachment=$matches[1]&feed=$matches[2]', | |
$cat_base.'(.+?)/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$'=>'index.php?attachment=$matches[1]&feed=$matches[2]', | |
$cat_base.'(.+?)/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$'=>'index.php?attachment=$matches[1]&cpage=$matches[2]', | |
$cat_base.'(.+?)/[^/]+/([^/]+)/embed/?$'=>'index.php?attachment=$matches[1]&embed=true'); | |
foreach( $rewrites as $regex => $match ) { | |
add_rewrite_rule( $regex, $match, 'top'); | |
} | |
} | |
add_action('init', 'custom_rewrite_rule', 10, 0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment