You don’t need to use any code for this. You just need to:
- Go to your /wp-admin/options-permalink.php page
- Select the ‘Custom Structure’ and enter:
/%postname%/%post_id%/
- Then press the ‘Save’ button
Related Posts:
- Is it possible to get a page link from its slug?
- Remove parent slug for child pages
- How to Remove Slug From Database?
- Remove parent slug for child pages
- Change author slug and functionality
- Share same Slug for a Custom Post Type and 2 Taxonomies
- Add prefix to page URL based on the page template
- get_permalink returning site home url instead of the url of slug being passed
- Passing the JQuery string to Worldpress URL
- wordpress how to replace url /bar with foo/bar for custom post type
- Bulk append URL (add word to slug)
- add_rewrite_rule – Page Slug from “/foo-bar/” to “/foo/bar/”
- How are WordPress Page URLs affected by permalink settings?
- Page content doesn’t display when published but does when previewed as draft?
- Subdomains pointing to a permalink URL
- How do I structure my permalinks in WordPress?
- Change all pages permalinks instead of hierarchical to have id of the page
- Need help with add_rewrite_rule
- remove “index.php” from permalinks
- How do I add /blog/ as a prefix to permalink structure for blog posts, tag pages, etc.?
- Passing and retrieving query vars in wordpress
- Permalink format: singular or plural
- How does WordPress handle permalinks?
- Pretty permalinks for search results with extra query var
- WordPress slug issue with non-latin characters
- How to get pretty URLs with add_query_arg in permalinks
- Creating custom permalink structure for languages
- Custom post type permalink endpoint
- How can I reverse engineer a Permalink to Find the Page?
- How to remove dates from existing permalinks?
- Getting the Site URL Including the Front Base
- Using $_GET variables in the URL?
- Removing the redirect after changing a page’s slug
- Must slugs be unique?
- How does wordpress keep track of post id when post id is not used in permalinks?
- Stop WordPress from reserving slugs for media items?
- Including category-base in a post permalink results in 404
- Change slug on post creation
- How can I store page ID in a post instead of other selected permalink?
- WordPress thinks my custom route is a 404
- Prevent WordPress from abbreviating-long-slugs…-in-the-admin
- Post type child of another post type
- Page begins with number, WordPress adds 2
- How to prevent apostrophes and quotes from appearing in permalinks?
- Date based URLs for custom posts and pagination
- Removing hierarchical pages in the permalink
- How to add a custom URL placeholder to author archives?
- How to custom change author base without $this->front?
- URL rewrite based on a custom field value
- Can WordPress realistically handle a site with 500 ‘pages’?
- Why don’t WordPress post slugs allow accents?
- Update URL Snippet to Canonical Permalink URL
- Is It A Good Idea To Change Author Slug (user_nicename field) Directly In MySQL DB?
- How to prevent the default home rewrite to a static page
- How can I force WordPress to redirect to canonical permalinks?
- When creating a WordPress page, a “-2” suffix is added to new pages’ permalinks
- “.#[random-char-string]” being inserted at end of URLs
- Subdomains to pages
- How to i18n slugs for templates?
- Passing variables through permalink structure
- How to change author base without front
- permastruct for custom post type not working in one of four cases
- URL Rewrite + Page + Custom Post Type = Unusual Redirect
- Broken wordpress permalinks on pages only
- Handle category name URL rewrite before different post type slugs
- Pretty Permalinks
- Make post slug have priority over category slug
- How to create a permalink structure for posts in a specific category
- How to get a page url by a page id?
- How to remove the index.php in the url?
- How to make draft posts or posts in review accessible via full url / slug?
- How to map permalinks with accented letters to sanitized slugs?
- Remove subfolders from URL
- Replace WordPress %postname% suffix with %postid%?
- Prepend meta_value to permalink of post
- Add custom directory in URL
- Limiting the number of words or characters in the slug/permalink
- Using two permalinks for one post
- flexible rewrite ‘ramble’ URLs with WordPress
- How can I Rewrite a ‘page’ URL based on query string parameters?
- Custom rewrite rules for a $_GET request
- Nice RSS Feed URLs for each custom post type
- Change the custom post type permalink
- Custom rewrite rules for feeds of custom queries (query_var query strings in URL)?
- custom naming of search permalink /search/
- Auto 301 to full post permalink? (using /posts/%post_id%/%postname%)
- Relative or Absolute Paths for Flash Video Player Files
- Put post ID on the custom post type URL
- Rewrite url / permalink for default archive – yearly / monthly
- Should I use relative or absolute urls when pointing to internal pages
- How to change the permalink structure of a master page?
- Rewrite user profile URL to be human friendly
- Gutenberg Editor: dynamicaly change slug field with an ACF field
- Plural Category Base Slug On Category Archive Page
- Why I can’t change the permalink of this page?
- Random Alphanumeric Key URLs
- How to edit the slug/permalink in Gutenberg?
- Make attachment pages require a base url
- Permalinks, Rewrites, Get Variables, Oh My!
- Using WP rather than .htaccess to redirect pages/posts