This code adds the subid parameter if does not exist to the current URL.
Use this plugin to insert the php code:
https://wordpress.org/plugins/my-custom-functions/
But you need to use add_action() to call this function somewhere.
function my_change_url() {
global $wp;
$current_url = home_url(add_query_arg(array($_GET), $wp->request));
if ( empty($_GET['subid']) ) {
$cuser = wp_get_current_user();
$username = $cuser->user_login;
$current_url = add_query_arg(array($_GET), $wp->request);
$current_url = add_query_arg('subid', $username);
$current_url = home_url($current_url);
}
return($current_url);
}
OR
You may use a shortcode:
add_shortcode('affiliate_subid', 'my_change_url');
Put the short code anywhere on a page:
[affiliate_subid]
Related Posts:
- How can I modify the permalink via a filter?
- How do I know what variables are passed in a filter/action and what their meaning is?
- Newbie question: no index.php? in my plain wordpress permalink
- Change links automatically to affiliate links
- Rewrite sub folder dynamically with country code in WordPress using PHP
- Use WordPress’ URL rewrite engine
- Returning a value from a PHP page
- Rename “Portfolio” slug?
- How to rewrite URL with PHP variables with htaccess to a normal looking URL?
- Static variable and add_rewrite_rule?
- Nesting if statements to echo only one string based on what tag was filtered?
- How to change home or site url using action hooks or filter?
- Why do WordPress rewriites seem to work differently for posts vs pages?
- Performance impact of rewriting WordPress URLs
- Is sanitize_title_with_dashes formatting function too liberal (in terms of accepted characters)?
- Get value from shortcode to do something
- Changes in permalink structure in WordPress and how to apply to in-site links
- WordPress Persistent connection rule does not work for “posts”
- Append query string to all URL’s
- custom rewrite rule help! Custom rewrite rules not applying to custom post type
- subdirectory index.php is not working
- Use URL Rewrite as well as $_GET parameters in URL?
- How to modify URL (add GET values) after front end form submission?
- parts of url disappear when using # inside href=”” [closed]
- Create custom permalinks to show Custom Post Type’s relationship?
- Add .htm extention to a custom taxonomy
- Help with .htaccess and Login with Subfolders
- WordPress add_rewrite_rules for custom URLs ending in .html
- Does anyone know all parameters of get_comments()
- Where is this function’s callback getting its arguments from?
- Rewrite with pagination /foo/page/2/ to posts of a given category, page 2
- Divi change project category slug
- How to add a rewrite endpoint to unattached media?
- How do i add slugs to a URL, but still redirecting to the same page
- Nginx WordPress and another Web app URL structure
- Custom post type url Rewrite (conflicting with page url)
- WordPress Rewrite Rule
- Why is home page content not displaying with this rewrite rule?
- Modifying WP URL handing code?
- How to deal with a GET variable of ‘name’?
- How to define a rule in functions.php that ONLY disables the default wp functionality that undesirably changes ‘&’ to ‘#038;’?
- Unable to display multiple parameters from url by javascript through shortcodes
- Test the existence of a page/article by its URL, taking in consideration the URL rewriting by filters
- url not using query string no longer working
- How to pass parameters in wordpress shortcode?
- Show data obtained from a function and place it in a shortocode function
- Current WordPress Page Title as Search Parameter into A Tag
- Get posts from year from URL
- How does one make a URL return dynamic JSON with custom Content Type?
- How Can I Display the Last Modified Date for User Profiles on WordPress?
- URL rewrite rule
- How does WordPress rewrite URLS using its PHP scripts
- Loop 1 user randomly
- How can I turn a url with get method as a clean url with segment as the get method?
- How to change this internal image link parameter using PHP?
- How to pass parameter that ends up being part of a class name with wordpress shortcode
- WordPress Rewrite Issue
- How to print redirected query string variables to the page?
- Multiple URL from Custom post name
- Why isn’t my custom function kicking in from my functions.php file?
- Difference in Get Variable Location
- WordPress adding in site URL to header links
- Dynamically append custom post type to end of url
- Shortcode to include PHP file, pass various parameters to include?
- WordPress add parameters with friendly url structure
- Custom taxonomy with page post type – WordPress
- How to check from which page the user is coming to the current page?
- Execute only on a certain page
- Type hinting and void return question
- Replace comment avatars and links at the same time
- Stumped – Ajax Response Returns 0
- Upload Image in a WordPress page using PHP
- Get Custom URL For Custom Taxonomy
- Can anyone offer any help with this function?
- Show meta box only for default page template
- Display related posts without a plugin
- load ajax using admin-ajax.php
- Create a WordPress shortcode using PHP [duplicate]
- How do I get the content excerpt of the recent post?
- Save Custom CSS file in the upload folder dynamically?
- How to check if a category has a parent and child categories?
- Accessing Global Vars & Functions in custom php page
- Load Javascript for a widget WordPress
- Links to previous/next month archives
- Workaround for og:image unsupported webp image type, Yoast SEO?
- Add a product category to a specific product via a button
- Creating a checklist with ACF and I cannot figure out how to add all iterations to an array that I’m creating
- Add Product Permalink in woocommerce admin order page
- Proper use of Output Buffer for a whole php clas
- How do I make comment-reply-button with that takes to comment reply form on click
- ERR_TOO_MANY_REDIRECTS / To Force SSL Logins and SSL Admin Access
- How to find the function which is outputting Array
- How can I include a file related to blog URL? Nothing seems to work
- Where are Sessions are being started? [closed]
- Object of class WP_Post could not be converted to string while trying to console.log wp_get_nav_menu_items
- Check radio get value to array
- Your PHP installation appears to be missing the MySQL … After deleting and restarting from cpanel
- WordPress Query -> Ajax Query
- Can WordPress support Website (19GB database) Should I move Our WordPress Website to a custom one using Laravel or any other PHP framework?
- WordPress Importer Call to undefined function set_time_limit()