Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress shortcode strips slashes from inline style?

I'm having an issue where I'm trying to set the background image of a div using an inline style (to display a featured image from a post). The shortcode is something like:

[all-systems]

And the handling function is something like:

$markup = '';

$img = get_the_thumbnail(...); 

// if I die($img) at this point, I am getting a valid link to my image like
// http://somedomain.com/wp-content/uploads/2015/03/pic.jpg

$markup .= "<div style='background-image('" . $image . "')>...</div>";

return $markup;

The resulting markup that the shortcode spits out is correct with the exception that the /'s in my background-image url are missing and replaced with spaces. So the background-image literally looks like:

http:  mydomain.com wp-content upload 2015 03 pic.jpg

Is this a protection that wordpress is "helping" me with? Anyway around this?

like image 808
Greg Avatar asked May 14 '26 19:05

Greg


1 Answers

There is an old discussion here about the "why/reasoning behind it" that doesn't really resolve anything...

However, what I've discovered, if you take out the quotes and just print the link without the quotes, it works fine.

$markup .= "<div style='background-image(" . $image . ")>...</div>";

It's what the previous answer essentially did, using printf instead.

like image 196
babybunnies Avatar answered May 17 '26 10:05

babybunnies



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!