Literally found the answer 10 minutes after posting this question and spending a couple of hours on it before asking. Simply hook your function to post_link! 🤦
public function __construct() {
add_action('post_link', [$this, 'post_links'], 10, 2);
}
public function post_links($link, $post) {
if ($post->post_type === 'post') {
return site_url('slug/'. $post->post_name .'-'. $post->ID);
} else {
return $link;
}
}
Related Posts:
- Need help with add_rewrite_rule
- remove “index.php” from permalinks
- Custom post type permalink endpoint
- How to add a custom URL placeholder to author archives?
- URL Rewrite + Page + Custom Post Type = Unusual Redirect
- Make post slug have priority over category slug
- Using two permalinks for one post
- flexible rewrite ‘ramble’ URLs with WordPress
- Change the custom post type permalink
- Custom rewrite rules for feeds of custom queries (query_var query strings in URL)?
- Rewrite url / permalink for default archive – yearly / monthly
- Permalinks, Rewrites, Get Variables, Oh My!
- Change permalink for a single post entry
- How to Modify Existing Rewrite Rules?
- rewrite_rule for custom post type doesn’t affect get_permalink
- Add ‘articles’ prefix before blog posts url without affecting pagination
- custom permalink/shortlink with base62 encoded post ID
- When is it a good idea to build a permalink structure from scratch?
- WordPress not respecting template hierarchy (fetches index.php instead of single.php or page.php)
- Call to a member function add_rule() on a non-object
- I need a custom permalink for my website
- Permalinks: Page Not Found
- Why is add_rewrite_endpoint incompatible with /%category%/%postname%/ permalink structure?
- Re-write specific custom post type category URL to go to another page
- Remove custom taxonomy base from URL
- remove sub-category of Custom Post Type from permalink structure
- add_rewrite_rule not working for me
- Is a permastruct possible on pages?
- Using WP Rewrite, but just not “getting it”
- Rewrite rule for a query string
- Share same Slug for a Custom Post Type and 2 Taxonomies
- How to remove specific category from URL in WordPress
- Rewrite CPT permalinks and include WPML language
- Custom permalink leads to index page
- Rewrite rule intended for CPTs gives 404 for pages
- Permalink structure between 2 custom post types and a taxonomy
- Permalinks only for posts
- Custom rewrite rule ignored
- wordpress how to replace url /bar with foo/bar for custom post type
- Getting back a permalink from custom url
- Order custom post type posts by custom field with pretty URL
- Adding URL prefix for foreign language support
- Exclude single page from permalink rule
- help to remove last trailing slash using add_rewrite_rule
- add_rewrite_rule – Page Slug from “/foo-bar/” to “/foo/bar/”
- How can I set up a secondary permalink structure?
- Rewrite rule not passing variable
- How to Use metada Value in Url and is it possible? [duplicate]
- Safest way to create a custom permalink
- corrupted URLs – can’t leave starting page
- rewrite based slug standar post wp
- Create different permalinks for same post
- remove SLASH on single_post but KEEP on categories and parent pages
- Multiple Taxonomy Items for Separate URLs
- Multiple URL rewrite rules and get every prams
- Using a template file for a specific custom URL
- WordPress Multisite ABSPATH and get_home_path() to check for htaccess or web.config file
- Redirect page to homepage, keeping URL
- how to have same rewrite rules for 2 different post type?
- Permalink structure /page/page/cpt-post gives 404 with pagination
- What permastrusture tags are generated out of the box right after creating custom post types and taxonomies?
- No Ones Been Able to Override my WordPress Rewrite Rule Issue!
- Rewrite posts url as they’re all children of a page
- a way to support totally different url structure
- Multiple Permalink Patterns for one page
- Pretty Filter URL
- WordPress Pagination Custom Rewrite Rule for Pages
- rewrites and custom links in page need help with add_rewrite_rule
- Prevent guessing slug
- WordPress permalink still not working (error or not understood?)
- WordPress custom permalinks, pages are now 404
- Add additional URL variations for a Post
- How do I add /blog/ as a prefix to permalink structure for blog posts, tag pages, etc.?
- Permalink format: singular or plural
- permalink independent on the post’s name stored in the database
- URL rewrite based on a custom field value
- How to change author base without front
- Permalinks so that one custom post type appears to be a child of another, not working
- How to create a permalink structure for posts in a specific category
- How to map permalinks with accented letters to sanitized slugs?
- Prepend meta_value to permalink of post
- Add custom directory in URL
- Custom rewrite rules for a $_GET request
- Put post ID on the custom post type URL
- Remove the Parent category from the permalink but leave the child category
- Apostrophe in permalink results in page not found
- Multilanguage URLs
- Attachment Page Permalink/URL Rewrite Issue. How to change the actual rewriting?
- Does changing a post title of a published post automatically change permalink?
- How can I use get_post_meta with add_rewrite_rule to build custom permalinks?
- How can i have a custom post type with more slugs for each post?
- URL rewriting: removing the site’s basename for a specific category
- Custom permalink for specific category
- Unable to get /%postname%/ permalinks working, 404 on all links
- Permalink structure with custom taxonomies and custom post type like /parent-tax/child-tax/custom-post-type-name (with no base name)
- Rewrite Rules returning wrong data
- Passing the JQuery string to Worldpress URL
- permalink and add_rewrite_rule – error 404
- WP-e-commerce (getshopped) – Annoying permalink issue [closed]
- IIS7.5 URL rewrite pboblem on index page