To encode the URLs on the source page, in this case ‘home’:
function append_query_string( $url, $post, $leavename ) {
if ( $post->post_type == 'post' ) {
$url = add_query_arg( 'source', 'home', $url );
}
return $url;
}
add_filter( 'post_link', 'append_query_string', 10, 3 );
This adds ?source=home
to the end of post link URLs on the home page.
To decode the URL on the target page ie. create a variable with ‘home’ detected as its value in this example:
$posturl = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
parse_str( parse_url( $posturl, PHP_URL_QUERY ), $get_args);
$source = $get_args['source'];
Thanks to Laxmana for the suggestion.
Related Posts:
- How to use wpLink without editor?
- How to print translation supported text with HTML URL
- Get the prev / next page links only (not title, etc)
- How to re-enable the links manager?
- Links redirecting to localhost after migration to server
- Count and show Clicks on external links in a single page/post
- How to use wp_rel_nofollow to add nofollow to external links only?
- get_category_link() is returning nothing
- Is there any way to set default for “Insert/Edit Link” to “Open link in new window”?
- root-relative links for multiple parked domains
- Get link value only from the_content()?
- Can’t add a class to links in the visual editor since WP 3.1?
- What is the canonical way to link to pages?
- HTTPS page link in menu
- How do I remove or disable “Or link to existing content” in “insert link” dialogue?
- Link Category Description
- Auto-embed link info from URLs in link post format?
- programatically change href to onclick=window.open
- Disable automatic content hyperlinking
- Deep linking to an accordion tab with Visual Composer
- How to add/change a value of $wpdb property/var?
- Need advice on how to add links in users profile page?
- How to hide a customization link themes menu in wordpress?
- Custom Post Type archive link in WYSIWYG editor
- Add Link Text Back to Insert/edit link Box
- How to list all external URLs that I have posted on my WordPress blog?
- How do I make my navigation bar link to an external page?
- Is there any way of changing the post order via user click?
- Creating a navigation link to my front-page
- How to remove author name and link from a shared link preview?
- Relative links for performance?
- Dont’t change active Button while I’m listing a category?
- How do i set the read more link?
- Plugin for wikipedia style references in WP?
- Problem creating an edit link for a custom post type
- How to convert all links to no follow links of particlular section of a webpage
- After duplicating site to a sub folder, links send user to original site
- Links are not working on All Plugins Page
- Twitter links in widget don’t work?
- WordPress links https overwrite issue
- plugin admin subpage title and links in menu not highlited at current page
- Change Read More in Child theme
- Add text excerpt and pictures to hyperlinks?
- WordPress changes URL?
- Parent/child pages and link structure the right way
- Link below the footer removal
- How to change all external links to “nofollow” but only for Contributor role?
- Exclude uploaded files from appearing in the excerpt()
- link to single most recent post, regardless of category
- Change description of my Jetpack facebook shared links [closed]
- Do you use links?
- Add the title attribute to links
- WordPress relative links for regular non image links
- Trouble getting the Blog page to show up correctly
- How Do I Link My Whole Featured Article Image?
- Insert wrap span tag around contents of a link tag automatically
- Remove nofollow from specific internal links
- Change homepage’s logo link [duplicate]
- Allow insecure embedded content in a SSL secured website
- remove the title attribute from links [closed]
- How to prevent WordPress from abbreviating long slugs?
- Embed/Link external web pages into my WordPress blog (Like Facebook grabs Image, Title, and Description)
- Previous and older set of posts links
- Page to show a link to every file in an directory
- Put password on a wordpress link in a article
- Links In Sidebar not displaying
- Display category page number links for older posts
- Blogroll/Lins Menu not visible in my backend?
- How to get Facebook to see YouTube/Blip embeds when sharing a link?
- How do I exclude main pages and link only to sub pages?
- What’s the URL to my blogs (from my home page – which is a “page”)
- Snippet to Format Elementor Text Box Throws Error
- how do I turn off whatever causes links to be embedded as URL’s site title
- How to make entire in blog post page linked?
- how give a link to an Elementor Pro widget with variable part
- ddnss linking problem
- Rotate prefix for external domain links using functions.php?
- Making download links from short code
- Displaying Most Recently Edited Post
- Best practice and technology to Offset anchor links
- how to display country/region/subject/post reasonably
- WordPress Intranet Link Not Working
- Reuse links in a post across different languages
- Prevent “nofollow” from Being Inserted into BBPress Posts
- WordPress link management
- How do I change the “href” link that corresponds with an “li class” statement?
- Links offset on my page
- What could interfere with changing iframe contents with href?
- How to link to specific part of a page in wordpress permalinks
- On main page link image to post page, on post page link it to it’s own image?
- Removing links from posts in WordPress
- WordPress link to show popup box
- remove the ‘page’ URL parameter in previous/next posts link
- Internal linking search box not working – WP 3.2
- WordPress: How to make a subsubdirectory
- External Links Not Working [closed]
- How do I edit a links published date?
- I’ve been trying for an hour to remove the underline from links; I don’t understand why something that should be so simple is so difficult [closed]
- Short website link for all post
- gallery link not displaying photos