You can use the post_link filter to do this.
Example:
function modify_post_link( $url, $post, $leavename=false ) {
if ( $post->post_type == 'post' ) {
$url = str_replace(home_url(), 'https://preview.domain.com', $url);
}
return $url;
}
add_filter( 'post_link', 'modify_post_link', 10, 3 );
In fact, with this you don’t even need your previous filter for get_sample_permalink
.
Related Posts:
- Need help with friendly URL’s in WordPress
- Why does WordPress 3.0.4 keep deleting the contents of the .htaccess file?
- how to flush custom author rewrite rule
- Add filename to attachment page url
- Creating Search Engine Friendly URL’s with Word Press
- WordPress slugs and 404 handling takes preference over folders in site root?
- How to encode author ID in the author permalink
- WordPress Custom File Permalink
- How can I create a permalink with two categories, with the order based on the parent category?
- How To Load an HTML File As A WordPress Page (With No 301/No Redirect)
- Create a url structure for my blogs based on categories and sub-cats
- Woocommerce product permalink not working
- Create page as a file in my theme?
- Don’t change Custom Post Type slug to unique value
- Add or Create Custom Structure Tags to Permalink
- How do I change my permalink structure to a custom structure on an established blog?
- getting a 404 page for all pages except home. possibly permalinks
- Create Miltiple Category Base
- How to get Previous Visited Page Information
- Adding a custom field to a slug
- how can custom permalink structure use for specify custom post type
- URL issue after setting up Custom Structure in Settings >> Permalinks
- Custom permalink structure for posts in certain categories
- How to add rewrite rule for product compare page?
- How to add a static text at end of a wordpress permalink
- Combine Categories & Custom Taxonomy
- Structure of post types for TV Shows and episodes
- Smarter Document Management links between three WordPress sites sought
- permalink of word press in htacess
- For one linked image per post, override that link with a permalink when on the main page
- I need to display post related info
- How to keep the /blog slug even in single post slug
- Show post content in two different places without redirect
- Permalink Listing WordPress
- Redirection after Category Change for Custom Structure
- Looking for a lightweight theme using WP3 new tags and features (not 2010) [closed]
- Creating my own Admin Forms in a WordPress CMS?
- Custom taxonomy: same terms, but for different years
- Best practices for A/B testing?
- Editing the Number at the end of Page URLs / Editing Page Slugs
- Can I use $wpdb for my custom tables in the WordPress database?
- How to get input_attrs in the sanitize function?
- Integrating MailChimp newsletters as post
- Remove POST_TYPE from custom post type permalink
- What is WordPress file encoding?
- Change from /wp-admin/ to something else?
- Adding “Interesting Tags” & “Ignored Tags” like StackOverflow.com in a WordPress Blog?
- Auto add taxonomy if post has category
- Add a containing DIV to core Gutenberg blocks
- Allow comments without approval for custom content type
- Add ‘Right Now’ widget to custom dashboard
- Are there any security issues with setting the WP_INSTALLING constant to true?
- Naming script handles right way
- How to edit pages after installing WP
- Exclude custom taxonomy tag from loop
- Multiple WordPress outside wordPress installation?
- WordPress generated links – menus and home_url() – not using https despite settings
- How to use
- How to check if a custom user profile field is empty
- Author Tracking Code!
- Change the Labels of Users to Customers in Admin
- How can I create a second multisite network in a subdirectory?
- List top 5 authors with most posts
- CSS Styling a specific page
- Plugin to allow registered users to customize their layout [closed]
- Can Username and Password be passed to WP Login page in an IFrame?
- Custom Columns WordPress Admin
- Get users based on month ACF datepicker field
- Trigger Customizer Publish (save) Action
- Edit value=”” of a button in child theme
- External Link Button Under Post Excerpt on Index.php
- WP function duplicating body content
- How to Remove the Custom Theme Panel from a Theme?
- title tag function
- How to do multi site setup
- Is it possible to edit a wordpress category with Gutenberg?
- How to change Login default blue admin color?
- I want to change url structure of my created archieve pages
- Simple Add To Cart Ajax Button
- How to prepend block content in getSaveElement filter?
- Upload advanced custom field text link array with csv
- Advice on how to structure a custom plugin
- How can I delete the word `Category:` from page titles? [duplicate]
- How can I add category variable inside posts?
- Create page when a new site in multisite network is created?
- Figuring out how to create “Option Pages” in WordPress admin
- Including a Customized Initialize File with a wordpress header
- Link to a new page into a plugin
- Change the – WordPress from titlebar?
- I can’t override CSS
- Url rewriting on custom post with CPT UI plugin
- Add field to post form
- Setting variables as custom field values
- Which IDE best for WordPress Development? [closed]
- How do I fix the url when clicking on portfolio item?
- Is it possible to show related posts on WordPress attachment pages?
- How to add filters to my site?
- How to use same username account for multiple users?
- Advanced Custom Fields in WP_Query: Href Returning Empty
- Unable to edit the 1Homepage