Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

WordPress add query string to URL

PHPfunction shapeSpace_add_var($url, $key, $value) {
	
	$url = preg_replace('/(.*)(?|&)'. $key .'=[^&]+?(&)(.*)/i', '$1$2$4', $url .'&');
	$url = substr($url, 0, -1);
	
	if (strpos($url, '?') === false) {
		return ($url .'?'. $key .'='. $value);
	} else {
		return ($url .'&'. $key .'='. $value);
	}
}
Source by wp-mix.com #
 
PREVIOUS NEXT
Tagged: #WordPress #add #query #string #URL
ADD COMMENT
Topic
Name
4+7 =