append url parameters to all links

1. Track Affiliate via Cookie To track the affiliate source you can use a Cookie for internal tracking. In that case you only need to modify external links. add_action( ‘plugins_loaded’, ‘so265278_affiliate_check’ ); function so265278_affiliate_check() { $is_affiliate = ! empty( $_GET[‘ref’] ); if ( $is_affiliate ) { setcookie( ‘affiliate’, $_GET[‘ref’], MONTH_IN_SECONDS ); } } Now you … Read more

Custom Post Type rewrite rules not working, how to alter the rewrite order?

While you’ve found the problem already, here is some basic code to move a specific rule to the end of the rewrite rules with the rewrite_rules_array filter for people stumbling across a similar problem. Say I want to move the rule for ([^/]*)/([^/]*)/?$: add_filter(“rewrite_rules_array”, function($rules) { $keys = array_keys($rules); foreach($keys as $rule) { if($rule == … Read more

Remove special characters in a URL

http://www.example.com/ar/shop-listing/health-beauty~@/#$&&&%%$%3Cscript%3E/ In this particular URL, everything after the # (hash) is the fragment identifier and is not sent to the server by the browser, so cannot be blocked server-side in .htaccess. The server only sees: /ar/shop-listing/health-beauty~@/ If the # was to be removed from this URL then this would be a wholly invalid URL (because … Read more

Changing the search URL?

You can change the /search/ part to something else, like /topic/, but it will be harder to remove it completely, since that will conflict with WordPress Pages (is /banana/ a Page with the title “Banana” or is it the result page for the search term “Banana”?). To change the part, hook into the init action … Read more