Created
August 10, 2012 03:38
-
-
Save norcross/3310808 to your computer and use it in GitHub Desktop.
create clean attachment URLs
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
// clean URLs for attachments | |
// http://domain.com/?attachment_id=173 | |
// http://domain.com/attachment/173 | |
function rkv_attachment_urls($wp_rewrite){ | |
$new_rules = array(); | |
$new_rules['media/(\d*)$'] = 'index.php?attachment_id=$matches[1]'; | |
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules; | |
} | |
function rkv_flush_rules() { | |
$rules = get_option( 'rewrite_rules' ); | |
if ( ! isset( $rules['media/(\d*)$'] ) ) { | |
global $wp_rewrite; | |
$wp_rewrite->flush_rules(); | |
} | |
} | |
add_action('generate_rewrite_rules', 'rkv_attachment_urls'); | |
add_action('wp_loaded', 'rkv_flush_rules'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment