Shortcode putting html such as

This behavior is most likely intended, and can be disabled. However it might break other features too. There are a couple of workarounds, that you can try.

Break the Image URL and File Name

You can pass the arguments to your shortcode in the following way:

[theimg 
    path="https://s.w.org/about/images/logos/" 
    filename="wordpress-logo-simplified-rgb.png"
]

This will prevent the editor from parsing the URL, but you can get the values and put them together in your PHP code.

Use preg_match()

So, the editor converts the URL to a full HTML image? Fine, let him do it. After the editor passed the full image to the shortcode, we can use a preg_match in our PHP code to extract the URL:

preg_match( '@src="https://wordpress.stackexchange.com/questions/290646/([^"]+)"@' , $img, $match );

This will parse the $img content and return the src of the <img> tag.

Leave a Comment