Add Destination Query to Drupal Links

Last modified: 
Thursday, November 12th, 2015

How to add ?=destination=URL to a Drupal link with l().

 // Attach destination to login links.
$options = array();
$destination = request_path();
if ($destination) {
  $options['query'] = array('destination' => $destination);
$my_link =  l('Log in', 'user', $options);
print $my_link; // Outputs the link with ?destination=CURRENT_RELATIVE_PATH attached

The operator of this site makes no claims, promises, or guarantees of the accuracy, completeness, originality, uniqueness, or even general adequacy of the contents herein and expressly disclaims liability for errors and omissions in the contents of this website.