Support » Fixing WordPress » PHP Variable for current URL

  • Resolved jzacsh


    hello, I feel like this is uber-simple, but I’m not too familiar with PHP (I know/think I’ve seen it before in the code making up a theme I’ve used):
    I’m trying to figure out what the variable is for the current URL (for instance, if I could call that variable here, you’d see “”, because that’s the URL of this page)

    important: would I be able to use this right inside of a post? (I see there’s only a WYSIWYG and an HTML editor for posting, no input for PHP, would I need to use the “custom fields” or something?)

    thanks in advance for the help!

Viewing 11 replies - 1 through 11 (of 11 total)
  • esmi


    Forum Moderator

    Could you explain what it is you’re trying to do?

    hey sorry, must’ve had email notifications turned off for this forum.

    um, i’m trying to figure out how I can dynamically display the URL of my website from inside of a post. specifically, I don’t want to manually type into my post <a href="">...

    because I may change my domain, at which point the link ^ above would no longer be correct. I know that one solution would be to have a relative link like <a href="/">... which would be like my pointing to the root of the site, but that won’t solve my problem this time.

    thanks again for any help

    Hi, I’m trying to figure out how to reference “base_url” or my ‘wordpress site’ when i link to things. For instance, lets say I want to write a link in a blog post that’s:

    if i change my domain to, that link^ will break

    a solution (i hoped) would be:

    <?php $BASE_URL$ php?>/tags/tech

    [where $BASE_URL$ is simply a variable refencing the wordpress configuration setting that holds the invormation to “blog_url” and “site_url” in the settings pane]

    thanks in advance!! 🙂



    Forum Moderator

    You can’t use PHP within the post/page content area unless you first install a plugin like PHP Execution. And if you’re going to do that, why not use <?php bloginfo('url'); ?>/tags/tech?

    Moderator Mark Ratledge


    Forum Moderator

    Use these, from

    <?php bloginfo('template_directory'); ?> returns the active template directory
    <?php bloginfo('url'); ?>  returns URL of web root
    <?php bloginfo('title'); ?> returns blog name

    And use with a plugin that enables PHP in posts and pages, like Exec-PHP

    aah, a bloginfo function! thank you, this is exactly what i meant, I’ll test this out tomorrow,

    Thank you both so much!

    Just wondering if anyone knows of an easy way to take this 1 step further: the full URL of the page that is currently being displayed.



    To get the current URL, you can use a pretty simple PHP snippet (explained here: )

    Thanks for that acafourek.

    Just wondering, is there a built-in WP function that does it for WP-specific URLs? I built and used something similar to that WebCheatSheet one, but sometimes it returns WP URLs that end in .ico, .gif, etc. and not the main page URL.


    You can use get_permalink() function

    It doesn’t solve major problem here.
    If you are using 4 exmpl. google translator and you wanna keep your links accurate even on translated pages you need to generate links from your template… Pure php method will get google link after translation and you wont be able to use this function again.

    Anyone know’s a way to determine current page permalink (whenever it’s a category, page, post, or search page teplate)?

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘PHP Variable for current URL’ is closed to new replies.