Could you explain what it is you’re trying to do?
Thread Starter
jzacsh
(@jzacsh)
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
(@jzacsh)
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!! π
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?
Use these, from http://codex.ww.wp.xz.cn/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
Thread Starter
jzacsh
(@jzacsh)
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.
Thanks!
-WCC
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 )
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
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)?