Created
August 20, 2012 22:29
-
-
Save mjangda/3408633 to your computer and use it in GitHub Desktop.
Custom permalink structure for a bunch of post types
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
<?php | |
// Register our custom rule | |
add_action( 'init', 'qz_add_custom_permalink_rule' ); | |
function qz_add_custom_permalink_rule() { | |
add_rewrite_rule( '/(\d+)/(^/)/' => 'index.php?p=$matches[1]&name=$matches[2]' ); | |
} | |
add_filter( 'post_link', 'qz_custom_permalink', 99, 2 ); | |
function qz_custom_permalink( $permalink, $post ) { | |
if ( in_array( $post->post_type, array( 'post', 'article' ) ) ) // add other post_types here | |
$permalink = home_url( sprintf( '%s/%s/', $post->ID, $post->post_name ) ); | |
return $permalink; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment