How to use relative urls when working with a wordpress site
Are there any tips or suggestions on how to set up wordpress to 开发者_C百科use relative urls?
I wrote a little PHP function that I located in the functions.php file of my theme:
function get_theme_relative_directory()
{
return str_replace(get_site_url(), '', get_bloginfo('template_url'));
}
Using it in the theme files like this:
<link href="<?=get_theme_relative_directory()?>/style.css" type="text/css" media="all" rel="stylesheet">
Are you referring to when the editor, for example, inserts images?
If so, then I am not aware of any configuration setting to stop WordPress adding the full URL (eg. mysite.com/wp-content/uploads/image1.jpg) but you have the opportunity to edit it before clicking OK.
Yep, you can use my plugin: http://wordpress.org/extend/plugins/root-relative-urls/
It will convert all urls to root relative, including urls that are embedded via the editor. It will even convert rss feeds back to absolute (which is only necessary because companies like feedburner and feedblitz don't follow the html spec.)
The plugins that exist at the time of writing this lack complete coverage of the codebase. They only handle specific urls or specific scenarios. And you should never have to search & replace your database, Tim Berners Lee solved that problem way back in 1993.
Hope that helps and sorry I couldn't answer this question sooner, but I didn't write the plugin until a month ago or so :D
精彩评论