We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • A common problem when developing content in MODx is with anchor tags not working for the current page, due to the base tag required to properly maintain relative paths. To solve this, you can use the following very simple plugin (check the OnWebPagePrerender event):
    <?php
    $e= & $modx->Event;
    switch ($e->name) {
        case "OnWebPagePrerender" :
            $modx->documentOutput= str_replace('href="#', 'href="' . $modx->makeUrl($modx->documentIdentifier) . '#', $modx->documentOutput);
            break;
    }
    ?>


    NOTE: Be sure not to include the <?php ?> tags in the plugin editor...

    This should work in most situations, but let me know what you think or if you encounter any problems with it. I’ll add it to the repository soon.
      • 31037
      • 358 Posts
      Very nice! Two hours ago I was sitting wondering why I couldn’t get anchors to work. And now this! Great! laugh

      Works fine! smiley
        • 27376
        • 576 Posts
        Brilliant!

        Clever name too smiley
          • 11975
          • 2,542 Posts
          Hi,

          This one will work without changing the start id page in the plugin code


          <?php
          $e= & $modx->Event;
          switch ($e->name) {
              case "OnWebPagePrerender" :
                  if($modx->documentIdentifier != $modx->config['site_start']) {
                      $modx->documentOutput= str_replace('href="#', 'href="' . $modx->makeUrl($modx->documentIdentifier) . '#', $modx->documentOutput);
                  }
                  break;
          }
          ?>
          


          :-)
            Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
          • Nice tweak heliotrope ... care to put this sucker in the Resources library?
              Ryan Thrash, MODX Co-Founder
              Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
              • 6726
              • 7,075 Posts
              Indeed that would be cool, I missed it though I browse the forums daily, cool plugin smiley !
                .: COO - Commerce Guys - Community Driven Innovation :.


                MODx est l&#39;outil id
                • 18253
                • 34 Posts
                Is this plugin still working? I was noticing the anchor issue and found this thread.

                I created a plugin based on : Quote from: heliotrope at Jul 19, 2007, 01:00 PM

                Hi,

                This one will work without changing the start id page in the plugin code


                <?php
                $e= & $modx->Event;
                switch ($e->name) {
                    case "OnWebPagePrerender" :
                        if($modx->documentIdentifier != $modx->config['site_start']) {
                            $modx->documentOutput= str_replace('href="#', 'href="' . $modx->makeUrl($modx->documentIdentifier) . '#', $modx->documentOutput);
                        }
                        break;
                }
                ?>
                


                :-)

                and also made sure that OnWebPagePrerender was checked off on System events. All my anchors are currently sending me to the homepage.
                  • 7231
                  • 4,205 Posts
                  I used this plugin on my last project on 0.9.6.1 and it worked fine. I think I used the original release from the repository, I recommend using that one.
                    [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                    Something is happening here, but you don&#39;t know what it is.
                    Do you, Mr. Jones? - [bob dylan]
                    • 17755
                    • 21 Posts
                    I have the same problem than marco garcia...

                    Any idea ? rolleyes

                    [edit] Uhuhuh, fixed it by myself : try without the <?php ... ?> and it’s cool. Sorry... grin
                      • 7768
                      • 8 Posts
                      Have used all variants of the plugin siggested on this page and still all the anchors are going back to the homepage. I’m using version 0.9.5 and cannot upgrade yet (compatibility issues). any ideas fellas?