• Resolved Waningett

    (@waningett)


    Hi!
    I have created a custom theme in which I use several shortcodes that I wrote myself. I am new to the shortcode game, so I have a lot to learn… Here is my question:
    I have made this shortcode to simply add an image to some content after which j Query will do some other stuff with it. It all worked on my localhost, but not online. The problem seems to be the image link.

    here is the short code, where the id is the id of the attachment:
    [img id="123"][/img]

    then the short code itself:

    function sImg($atts, $content = null){
    	array(shortcode_atts(array(
    		"id" => '',
    		), $atts));
    	return '<div class="erb">
    	<div class="erb-img-wrap">
    		<div class="erb-img" data-src="https://mysite.com/?p='.$atts['id'].'"></div>
    		</div>';
    }
    add_shortcode('img', 'sImg');

    How can I change this so that the data-src actually points to the source of the image, and not as it now seems to the attachment page, with only the id?

    I hope I was clear enough in my question. I have been looking for an answer for several hours, but without any luck. I hope someone here will be able to help me!
    Thanks in advance!

  • The topic ‘Image link by id in shortcode’ is closed to new replies.