Title: PHP Variable for current URL
Last modified: August 19, 2016

---

# PHP Variable for current URL

 *  Resolved [jzacsh](https://wordpress.org/support/users/jzacsh/)
 * (@jzacsh)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/php-variable-for-current-url/)
 * 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 “wordpress.org”, 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](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/php-variable-for-current-url/#post-1159352)
 * Could you explain what it is you’re trying to do?
 *  Thread Starter [jzacsh](https://wordpress.org/support/users/jzacsh/)
 * (@jzacsh)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/php-variable-for-current-url/#post-1159597)
 * 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="www.site.com">...`
 * 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
 *  Thread Starter [jzacsh](https://wordpress.org/support/users/jzacsh/)
 * (@jzacsh)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/php-variable-for-current-url/#post-1159674)
 * 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:
 * **`http://mysite.com/tags/tech`**
 * if i change my domain to newsite.com, 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!! 🙂
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/php-variable-for-current-url/#post-1159675)
 * You can’t use PHP within the post/page content area unless you first install 
   a plugin like [PHP Execution](http://wordpress.org/extend/plugins/php-execution-plugin/).
   And if you’re going to do that, why not use `<?php bloginfo('url'); ?>/tags/tech`?
 *  [Mark Ratledge](https://wordpress.org/support/users/songdogtech/)
 * (@songdogtech)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/php-variable-for-current-url/#post-1159676)
 * Use these, from [http://codex.wordpress.org/Template_Tags/bloginfo](http://codex.wordpress.org/Template_Tags/bloginfo)
 *     ```
       <?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](http://wordpress.org/extend/plugins/exec-php/)
 *  Thread Starter [jzacsh](https://wordpress.org/support/users/jzacsh/)
 * (@jzacsh)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/php-variable-for-current-url/#post-1159679)
 * aah, a bloginfo function! thank you, this is exactly what i meant, I’ll test 
   this out tomorrow,
 * Thank you both so much!
 *  [WatchCount.com](https://wordpress.org/support/users/watchcountcom/)
 * (@watchcountcom)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/php-variable-for-current-url/#post-1159695)
 * 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.
 * Thanks!
 * -WCC
 *  [acafourek](https://wordpress.org/support/users/acafourek/)
 * (@acafourek)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/php-variable-for-current-url/#post-1159696)
 * To get the current URL, you can use a pretty simple PHP snippet (explained here:
   [http://www.webcheatsheet.com/PHP/get_current_page_url.php](http://www.webcheatsheet.com/PHP/get_current_page_url.php))
 *  [WatchCount.com](https://wordpress.org/support/users/watchcountcom/)
 * (@watchcountcom)
 * [16 years, 5 months ago](https://wordpress.org/support/topic/php-variable-for-current-url/#post-1159700)
 * 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.
 * -WCC
 *  [gauthamns](https://wordpress.org/support/users/gauthamns/)
 * (@gauthamns)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/php-variable-for-current-url/#post-1159721)
 * You can use get_permalink() function
 *  [megakozak](https://wordpress.org/support/users/megakozak/)
 * (@megakozak)
 * [15 years, 12 months ago](https://wordpress.org/support/topic/php-variable-for-current-url/#post-1159736)
 * 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.

## Tags

 * [php variable](https://wordpress.org/support/topic-tag/php-variable/)
 * [url](https://wordpress.org/support/topic-tag/url/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 11 replies
 * 7 participants
 * Last reply from: [megakozak](https://wordpress.org/support/users/megakozak/)
 * Last activity: [15 years, 12 months ago](https://wordpress.org/support/topic/php-variable-for-current-url/#post-1159736)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
