Support » Plugins and Hacks » Relative vs. absolute href links

Relative vs. absolute href links

  • I’m pretty new to WP, but not to php and programming. I’m bringing up a site that currently uses the “widescreen” template from Graphpaper Press – which uses the new 3.0 menu system.

    I need to point more than one domain address to the same WP site instance, and to have the site behave a little differently (e.g. hide the “Contact” page) depending which domain was used. It’s easy to test <?php $_SERVER[SERVER_NAME]; ?> to find out what domain the client’s browser requested, but then the behavior of the menu system gets in the way.

    The href’s in the menu links appear to always be relative to “Settings (-> General) -> WordPress Adress” in the admin menu (probably via bloginfo(‘siteurl’)…). That is, the menu gives absolute links based on the web address in the Settings. This means that no matter which $_SERVER[SERVER_NAME] was specified by the client browser, as soon as they’ve clicked a link I’ve lost original domain address and started using the one from Settings.

    Have I overlooked some functionality that would let me do what I’ve described? If I need to hack WP, I’d appreciate any tips on how to do it with minimal collateral damage. (I am using git; I’m generally in a good position to manage updates while preserving hacks).


Viewing 2 replies - 1 through 2 (of 2 total)
  • Since nobody spoon-fed an answer, I hacked one up (and it’s not as bad as what I initially described). Perhaps this will help somebody:

    I wrote a WP plugin called link-chameleon that hooks into the wp_nav_menu filter hook. Assuming the operative $_SERVER[SERVER_NAME] is in my list of domains, the bloginfo(‘siteurl’) portion of all links is replaced by $_SERVER[SERVER-NAME]. A second function in the plugin checks whether it’s a URL that requires hiding the contact page, and filters out that link if so. This takes care of the menus, but not all other links. In my case there aren’t very many (it’s not a blog site), so it’s no big deal – I just had to hack my header.php and footer.php.

    Then it hit me that robots.txt was also a loose end. I really only want one of the domains indexed. I created robots.txt.php, which generates URL appropriate content. I added a RewriteRule to .htaccess to redirect robots.txt requests to robots.txt.php. In order to prevent WordPress from generating the robots.txt output, I had to create a dummy robots.txt file, which is duly ignored due to the RewriteRule.



    I need to do exactly the same thing (i think). Could i try your plugin and see if it helps?


Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Relative vs. absolute href links’ is closed to new replies.