In WordPress site, when we are doing custom changes in theme or plugins, we may need to pass argument or variable through the WordPress URL. Here we hare going to learn how to Add query string parameter/arguments to WordPress URL.

1. For Single Value

( Using a single key and value )

$old_url = "";
$new_url = esc_url(add_query_arg( 'key', 'value', '$old_url' ));

2. For Multiple Values

( Using an associative array )

$old_url = "";
$new_url = esc_url(
                 'key1' => 'value1',
                 'key2' => 'value2',
                 'key3' => 'value3',

Note : Always use esc_url() before outputting the link because this function does not escape URLs and if output without escaping, would make the page vulnerable to XSS scripting.

There are currently no comments.