The site that I am working on uses the following "pretty" permalink structure:


But for a custom post type my client would like to avoid having a "pretty" slug:


How can the post ID be used in place of the slug for the custom post type?

I believe that this might be possible using WP_Rewrite, but I do not know where to begin.

1 Answer 1


This is what I use to rewrite custom post type URLs with the post ID. You need a rewrite rule to translate URL requests, as well as a filter on post_type_link to return the correct URLs for any calls to get_post_permalink():

add_filter('post_type_link', 'wpse33551_post_type_link', 1, 3);

function wpse33551_post_type_link( $link, $post = 0 ){
    if ( $post->post_type == 'product' ){
        return home_url( 'product/' . $post->ID );
    } else {
        return $link;

add_action( 'init', 'wpse33551_rewrites_init' );

function wpse33551_rewrites_init(){
        'top' );
  • Hi @milo this works me perfectly ... but i want some changes please can you guide me Mar 13, 2015 at 5:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.