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
- Remove slug of multiple custom post types with and without hierarchical
- Hide custom image sizes from media library
- How to implement WP_List_Table? WP_List_Table giving array instead of a value in listing table
- Would manually deleting the dumping data fix a “#1062 – Duplicate entry ‘1’ for key ‘PRIMARY'” phpMyAdmin error?
- Output data like WP’s plugin installer/updater
- Create placeholder text for wordpress search box [closed]
- Woocommerce product variation backorder
- Calculating a large number of MYSQL queries as customshort codes, slow
- Status 400 for AJAX POST Request with admin-ajax.php
- Is it possible to use Data URI image to set a post thumbnail?
- Log in / Log Out Custom Button
- stripping tags from excerpt in WordPress is not working
- Mixing variables into an array when inserting values
- How to disable delivery on certain date at checkout page in WooCommerce?
- Loop over Array and get the distinct ids
- Removing sidebar on category pages
- Hide publish date when update date
- Category Page Displaying all Pages
- Looping through dummy posts and showing them in the main index.php
- WordPress mysql deos not work with php7
- Need help with AJAX login to call php in functions.php to handle redirects based on user cap (role)
- PHP – Woocommerce 3.2 Add variable shipping insurance with multiple “else if ” conditions
- Shortcode Works for Logged in Users but Not Working for Guest
- ACF Images If/else
- problem multisite with blog id
- Attachments doesn’t update
- wp_customize_image_control default value
- Adding javascript files to WordPress and jQuery version
- How do I use CSS or PHP to customize WordPress Form Manager Plugin Table?
- problem with php function error
- How can precision be improved for the debug log timestamp?
- Redirect to current URL and append specified URL parameter on unsuccessful login through Elementor login form widget
- Add up all numbers from a WordPress query [closed]
- WordPress admin area not sending mail (but works with WP Mail SMTP, Test Mail, and PHP mail() function)