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
- Embed dynamic php snippets with parameters in a blogpost
- How to Dynamically Change the author_base URL Slug by Language in WordPress?
- WordPress add_rewrite_rule not working with page_on_front
- Custom plugin settings link doesn’t append current class to menu item when visited? Why?
- Make PHP work with HTML tags
- Does wordpress templates always in files or in database?
- WordPress admin-ajax.php 400 bad request
- Not connecting to database in file with multiple MySQL connections
- Which is the correct way to conditionally enqueue a CSS file?
- Custom Background by Page IDs
- how to remove colon and white space in a string by php
- Concatenate output of php function into string
- get_template_part for specific page
- Do wordpress create a new file for each new post?
- Error call_user_func_array() expects parameter 1 to be a valid callback when using image_size_names_choose
- Way to bulk make all my tags lowercase?
- Why File_exists returns true with or without ABSPATH?
- proper way to add css using functions.php?
- WordPress style.css not updating, only after theme reload
- WordPress automatically adds links to uploaded images
- $Wpdb post meta query is not working with mutliple meta keys and values? [closed]
- class_exists returns different values [closed]
- Remove author link wherever author’s name is display
- How do I create my own .php file with a code part and echo it on different pages?
- Security for data obtained from the database
- How to add specific meta tags to head of cart and checkout pages in woocommerce?
- post thumbnail, conditions, else wont work
- “Undefined index” error when saving empty array with checkboxes
- Adding logo to WordPress header
- is there a benefit in using a constant over get_stylesheet_directory_uri?
- I restricted wordpress by logged users. It’s possible exclude a page?
- WordPress displaying content from sub pages
- wp_dropdown_pages auto submit