Including data in the page for your plugin’s JavaScript

Nip over to Otto’s blog and read his post entitled don’t include wp-load, please which I’m in complete and total agreement with. I’d like to add to the solutions with the following method of adding data to your page for use by your plugin’s JavaScript: wp_localize_script. Continue reading Including data in the page for your plugin’s JavaScript

Adding GET params to a URL in WordPress with add_query_arg

I am finding myself using this function a lot now, and I constantly forget the function name:

add_query_arg();

It allows you to pass in some additional parameters, and a URL, and receive back the URL with the query string params added. For example:

$some_url = "http://simonwheatley.co.uk/?stuff=whatever";
$params = array( 'wp_siteurl' => "http://www.example.com" );
$some_url = add_query_arg( $params, $some_url );

This will result in a url something like this:

http://simonwheatley.co.uk/?stuff=whatever&wp_siteurl=http%3A%2F%2Fwww.example.com

Pretty cool, huh? So now you don’t need to worry about what parameters are already in the URL, you can just hand all that hassle to add_query_arg.

Update: See also remove_query_arg.