Вопрос

I am building a site on my test server, that will eventually be migrated to its own domain when it is finished. For this reason i am trying to find a way to dynamically link to certain images, so i do not have to change the links when i move the site.

Is there a way to use php to dynamically pull the site url (of whatever domain the link is currently on) and then set the relative path to the image file?

I tried the following code without success:

<img src="<?php bloginfo('url');?>/fft/wp-content/uploads/2014/05/rogue-fitness-logo.jpg">

any suggestions?

Это было полезно?

Решение

You can't run php in the WordPress editor. You can enable php execution in the editor, though it's not a good idea if other users will be editing. You can execute php, of course, in template and theme files.

And you can execute php in a widget if you use the WordPress › PHP Code Widget plugin.

But relative paths will work in the html editors and continue to work in most cases. See Relative URLs in Wordpress

But you can allow the test server or localhost domains to be inserted by the editor by WordPress, and then use interconnectit.com WordPress Serialized PHP Search Replace Tool to migrate the URLs. That tool correctly serializes/reserializes data in the database, so there is no breakage.

Другие советы

SOLVED:

I simply did the standard relative path: [./subfolder/path/to/image.jpg] and it appears to be working now. I totally spaced on that one. I forgot php doesn't work in the standard text widgets.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top