This is very simple to achieve with JavaScript. Place this at the bottom of your page, just before </body>
tag.
This will append ?pp=my-affiliate-id
at the end of your links. Just change the variable aid
value below:
<script>
// Change "my-affiliate-id" below to your actual affiliate id
const aid = 'my-affiliate-id';
// Append slash with affiliate id, only if an affiliate ID is not found in the link yet
const goglinks = document.querySelectorAll('a[href*="gog.com"]');
goglinks.forEach(function(el) {
if(!el.href.includes('pp=')) {
el.href = el.href.replace(/\?.*$/, '') + '?pp=' + aid
}
})
</script>
Related Posts:
- Menu Link Redirect Based on Username or User ID
- how to get permalink
- How to use relative links on my pages?
- How can I store page ID in a post instead of other selected permalink?
- How to get a page url by a page id?
- Why does WP not use relative links when linking pages?
- Social Media Links on homepage – within posts/post loop
- Change website URL without breaking links or images? WP 3.3
- Redirect user if it’s not logged in
- How to get this JavaScript working with get_permalink
- WordPress 3.1 not compatible with jQuery Mobile?
- I copied my site to another site but all links point to old site
- Best way to add internal link in widget
- Confusion about how a URL is being parsed
- Change in permalink structure made javascript cookie not work correctly
- why some permalinks adding characters/ruining links
- How to change old permalink?
- Migrated from Windows to Linux. Any bulk methods for fixing case sensitivity?
- How to eliminate permalink prefix in WordPress Multisite
- Get the url of a page template without using the page slug and ID
- How to generate a list of all urls
- Format HTTP links
- Edit permalink for certain pages
- cannot link a external url, present page url acting as parent url
- Can WP give a value a post ID?
- Moved site, Old links in pages still pointing to old host
- How to use page jumps to top of banner and page title?
- How to remove the link of an image on WP 4.2
- Create custom links for excerpts with php dynamically
- How can I see a list of all pages my WordPress site has generated?
- How to make different urls for some tags pages
- Gutenberg Editor: dynamically edit slug field based on ACF field
- A dash can replace a period in a link, how to fix it
- Edit Post Permalink option removed, looking for possible causes
- My WP homepage works, but the other pages don’t when accessing from out side of my network
- Can I link to content dynamically from a page to a new page?
- Propper way to set anchor and url param
- Find internal links to post
- rebuilding/ rewriting a url to make it SEO friendly
- Remove link function from oembed image or video
- How to change dynamic link to relevant post
- Difference and usage of uri (e.g. get_directory_uri) and absolute path (e.g. get_directory)
- Possible to hide parts of the slug from get_template_directory_uri and bloginfo(‘template_directory’)
- After changing permalink settings, everything works fine except for the two most recent posts
- Latin character conversion
- Why not working /%postname%/ with ajax serverinterval?
- Pretty links for PHP pages above WP /blog directory?
- Permalink / sub-template issue
- Permalink structure as code in back-end?
- Include other parameters in permalinks for better management of browser history
- What is the issue with our links? It creates a loop
- wp_get_attachment_url not working
- Make all internal links relative, or otherwise make a website accessible from multiple domains
- Can you customize the automatic permalink population on new posts?
- jQuery animate backgroundColor
- How to convert selected HTML to Json?
- Embedding instagram webpage inside an iframe
- Custom Taxonomy in Permalink of Post
- “.#[random-char-string]” being inserted at end of URLs
- Filtering comment permalinks when a condition is met
- How can I Rewrite a ‘page’ URL based on query string parameters?
- add_rewrite_rule with 3 or fewer matches?
- Mass Permalink Changer
- Attachment page 404 not found when image is attached to post
- What happens when permalink settings are updated?
- query_vars in plugin not working?
- How to speed up admin-ajax.php in wordpress
- How to stop WordPress from removing & from URL?
- Share same Slug for a Custom Post Type and 2 Taxonomies
- Custom Post Type Yearly Archive Permalinks
- Using window.onload with Ubermenu
- Passing the JQuery string to Worldpress URL
- Problem passing id-specific objects to javascript via wp_localize_script
- .htaccess rewriterule being ignored – tyring to remove dates from WP posts
- Close Fancybox, sumbit form data and redirect
- Properly embed javascript into WP (using function.php) – doesn’t work?
- Apply function only if end of url has /amp/ [closed]
- WordPress Permalinks 404 bug with “next” button
- Combine category AND custom taxonomy in permalink structure
- permalink and add_rewrite_rule – error 404
- JS behavior differs depending on page tree [closed]
- IIS7.5 URL rewrite pboblem on index page
- Ajax add to cart not updating Elementor mini cart totals
- Category blog URL 404
- Read more block is appending /#more-{post_id} to the link
- Why does one of my pages not have the option to edit the link?
- Giving specific category posts its own permalink structure returns 404
- jQuery for Fade Preload Causes My Site Favicon to Disappear from Tab of Browser
- Issue with wp_insert_post when modifying permalinks with “.html” extension
- while changing permalink, page redirected you too many times
- Why can’t I save permalink “360” for a page?
- show-hide based on select option jquery wordpress
- Internationalize Forum Posts Without Translating Them
- Where is wordpress redirecting wp-admin/admin/dashboard to wp-admin and how to turn it off
- Only homepage working correctly, 404 error on everything else
- Clear custom field when new tag is added
- Text in permalink
- custom permlink .htaccess file 404 Not Found error
- javascript not loading in wordpress
- URL issues with WordPress