Skip to content

Instantly share code, notes, and snippets.

@munirkamal
Created April 26, 2019 11:17
Show Gist options
  • Save munirkamal/b9db6dff8cb6ece83f02e58ecdfc612b to your computer and use it in GitHub Desktop.
Save munirkamal/b9db6dff8cb6ece83f02e58ecdfc612b to your computer and use it in GitHub Desktop.
My WP blog Rewrite Code
<?php
function my_custom_pt_link( $post_link, $id = 0 ){
$post = get_post($id);
if ( is_object( $post ) ){
$terms = wp_get_object_terms( $post->ID, ‘abc );
if( $terms ){
return str_replace( ‘%abc%’ , $terms[0]->slug , $post_link );
} else {
return str_replace( ‘%abc%’ , 'misc' , $post_link );
}
}
return $post_link;
}
add_filter( 'post_type_link', 'my_custom_pt_link', 1, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment