Function to replace home url of image with a shortcode string
-
hey,
I’ve added some code to my functions.php file to create a shortcode that outputs my home url….
//Shortcode to return home url function homeurl_func( $atts ){ return get_home_url(); } add_shortcode( 'homeurl', 'homeurl_func' );When adding media to page content, I wish to add another function to the functions.php to update the image url and link url so that the [shortcode] text replaces the home url part of the string. See below….
Instead of………
I would like…..
This would make it a lot easier when moving sites when going live, as I wouldn’t have to manually add the short code when adding media. Is this possible, and would anyone know where I would start to achieve this? I’m sure this must have been asked before but I can’t find any answer on it.
Many Thanks
A -
I didn’t mean to add links to the post, I forgot to add backticks around the code for
<a href="http://test.com/wp-content/uploads/2014/08/the-dean.jpg"><img class="wp-image-173" src="http://test.com/wp-content/uploads/2014/08/image.jpg" alt="the-dean" data-id="173" /></a>and…
<a href="[homeurl]/wp-content/uploads/2014/08/the-dean.jpg"><img class="wp-image-173" src="[homeurl]/wp-content/uploads/2014/08/image.jpg" alt="the-dean" data-id="173" /></a>So as you can see I wish to add the shorcode to the href too.
- The topic ‘Function to replace home url of image with a shortcode string’ is closed to new replies.