I have a client who is adamant that the permalink structure for pages must be along the lines of postname/postid, such as test-page/7.

I've gotten as far as adding the post name using $wp_rewrite->page_structure with the following code, which works fine.

add_action( 'init', 'custom_page_rules' );

function custom_page_rules() {
    global $wp_rewrite;

    $wp_rewrite->page_structure = $wp_rewrite->root . '%pagename%'; 

However, when I add %post_id%, it is not converted to the page's ID. Examination of the WP_Rewrite class reveals that there is no %page_id% placeholder. Is this possible to do and, if so, how can I achieve it?

1 Answer 1


You don't need to use any code for this. You just need to:

  1. Go to your /wp-admin/options-permalink.php page
  2. Select the 'Custom Structure' and enter: /%postname%/%post_id%/
  3. Then press the 'Save' button

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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