[wp-hackers] absolute URLs in plug-ins and custom types
Otto
otto at ottodestruct.com
Wed Jul 4 22:25:28 UTC 2012
On Wed, Jul 4, 2012 at 4:54 PM, Shasta Willson <shastaw at gmail.com> wrote:
> I'm not using the terms properly. When I said "relative", I really
> meant I code something like this:
>
> <a href="<?php bloginfo('url') ?>/whatever">
Just wanted to point out that this is slightly safer:
<a href="<?php home_url('whatever'); ?>">
> Which is NOT a relative URL once rendered, but does update if I change
> the site settings, as opposed to the plug-ins which require you to
> input a URL like this:
>
> http://testsite.com/wp-content/uploads/2012/01/cover.jpg
Not necessarily the best way, but
content_url('uploads/2012/01/cover.jpg'); would give you that. When to
use content_url() depends on the context though.
*Ideally*, something in the /uploads dir happened through the media
uploader, and you'd get the exact URL for the attachment using the
post_id for the attachment and something like wp_get_attachment_url().
Again, this depends entirely on context. More information is needed to
give a proper response.
-Otto
More information about the wp-hackers
mailing list