Add parameters to the current url
Wordpress allows to add one or more parameters to the current url or external url by using following function. This function returns a modified URL query string.
add_query_arg()
There are 2 ways to use this function- single key and value
add_query_arg( 'key', 'value', 'http://example.com' );
2. Associative array
add_query_arg( array( 'key1' => 'value1', 'key2' => 'value2', ), 'http://example.com' );
How to add parameters to the current url
Here get_permalink function returns a URL query string of current url.add_query_arg( 'key', 'value', get_permalink() );
How to add parameters to the post/page url
get_permalink is used to get post / page url based on post / page id.add_query_arg( 'key', 'value', get_permalink('10') );
No comments: