-
-
Save Irfan-Ansari/9505256 to your computer and use it in GitHub Desktop.
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