Forums

[resolved] PHP Variable for current URL (8 posts)

  1. jzacsh
    Member
    Posted 4 months ago #

    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!

  2. esmi
    Member
    Posted 4 months ago #

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

  3. jzacsh
    Member
    Posted 3 months ago #

    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

  4. jzacsh
    Member
    Posted 1 month ago #

    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!! :)

  5. esmi
    Member
    Posted 1 month ago #

    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?

  6. songdogtech
    Member
    Posted 1 month ago #

    Use these, from 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

  7. jzacsh
    Member
    Posted 1 month ago #

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

    Thank you both so much!

  8. WatchCount.com
    Member
    Posted 1 day ago #

    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

Reply

You must log in to post.

About this Topic