I created a node in drupal 7 and given it a url path alias of 'testing'. When I try to create a menu item that links to the path alias with an anchor, it throws an error enter image description here

If I do node/1#this it works, but again not with a url path alias.

Is there a work around?


You can add the full url with the anchor tag. Not the best for deployment but a work around.

| improve this answer | |

I found adding the page path without it's alias would validate the form.

For example: "node/1#top"

Although, I now have an .active-trail and .active class issue on the menu item/link.

| improve this answer | |
  • Did you ever find a solution for the active class issue? – sasdev Mar 1 '14 at 18:49

This works for me:

function phptemplate_url_outbound_alter(&$path, &$options, $original_path) {
    $alias = drupal_get_path_alias($original_path);
    $url = parse_url($alias);

    if (isset($url['fragment'])){
        //set path without the fragment
        $path = $url['path'];

        //prevent URL from re-aliasing
        $options['alias'] = TRUE;

        //set fragment
        $options['fragment'] = $url['fragment'];
| improve this answer | |

In search for an answer for my colleague I found a gist.

You guys can try it out.


I have not worked on this.

| improve this answer | |
  • Have you used this code? Did you find it worked? – JamiePatt Aug 26 '12 at 11:16
  • @InfluenceJamie No, I have not. – Hari K T Aug 26 '12 at 13:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.