WordPress.org

Ready to get started?Download WordPress

Forums

PHP & WordPress Code for Domain URL (4 posts)

  1. xdhirax
    Member
    Posted 8 years ago #

    Hi all,

    WordPress is full of php code to refer to the blogs location.
    *(In the examples below I use "{" & "}" instead of "<" & ">")*
    I need the code to refer to the url of the domain, even if wordpress is installed on a subdomain.

    For example if I want to place a link for the home page, I would use this
    {a href="" target="_blank"}Home Page{/a}
    for a site map I'd use:
    {a href="/sitemap.html" target="_blank"}Sitemap{/a}

    That works fine if the worpress blog is installed in the root of a domain or in a subfolder.
    It does not work accurately if the blog is in a subdomain.
    If I use the above, the urls show up as:
    {a href="" target="_blank"}Home Page{/a}
    which gives me:
    "http://www.subdomain.domain.com"
    instead of
    "http://www.domain.com"
    and
    {a href="/sitemap.html" target="_blank"}Sitemap{/a}
    gives me:
    "http://www.subdomain.domain.com/sitemap.html",
    instead of:
    "http://www.domain.com/sitemap.html" which I would like.

    I've tried {a href='$ require($_SERVER["DOCUMENT_ROOT"]);/sitemap.html"}Sitemap{/a}
    and variations of it to no avail.
    Help appreciated.

  2. ladydelaluna
    Member
    Posted 8 years ago #

    A little secret from an SEO person... It's actually slightly better for you to hardcode the ENTIRE link URL in!

    It's not that well known, but it's been discussed a lot in the world of SEO as of late, that it helps the SE's spider the pages faster than having to sort through dynamic code to find the right page.

    It's not practical, sure... but in your situation, I think it'd be the best solution.

  3. xdhirax
    Member
    Posted 8 years ago #

    Yes I was hoping to avoid that since I need to do it several times in several subdomains....

    What about using includes?
    For example an include file in the root of the site called "menu.inc", and in it all thats in there is:

    include $_SERVER[SERVER_NAME]

    And then on the wordpress sidebar I place

    {?php include("menu.inc"); ?}
    or
    {? include("/home/user/public_html/menu.inc"); ?}

    Would something like that work?

  4. ladydelaluna
    Member
    Posted 8 years ago #

    I'm honestly not sure - hopefully someone else can let you know on that one... I'm guessing it would serve the purpose (but again, I'm not sure since I've never messed around with that).

    I do know that includes won't negatively effect your SE rankings though, if that makes you feel any better! :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags