Blog

Fixing the pesky hastag (#) to %23 rewrite in Drupal 7

There’s been a post or two on drupal.org about hashtags (#) getting rewritten to %23.

This doesn’t cause a lot of problems in the main however, if you’re using them as anchors and/or to target something using jQuery, it’s not ideal.

The best solution I’ve found so far is to update the hook_url_outbound_alter() function in template.php or a custom module.

In this example, I’m using templete.php.

function MYTHEME_url_outbound_alter(&$path, &$options, $original_path) { if (strpos($path, '#') !== false) { $pathExploded = explode('#', $path); list($path, $options['fragment']) = $pathExploded; } }

Just replace MYTHEME with your theme name.

If you have a...

Tagged:Drupal