• Hello!

    I am trying to customize a given function for shortcode about a banner. The banner contains a title and a subtitle.But I want to add an image left to the title. the function is like this:

    function banner($atts,$content=null){
        ob_start();
    extract(shortcode_atts(array("title" => '', 'subtitle'=>'', 'type'=> ''), $atts));
    
        if($type == 2){
    	   return '<div id="banner" class="banner-2">
                <div class="site-slogan">
                    <div class="slogan-inner clearfix">
                        <h2>'.$title.'</h2>
                        <h2>'.$subtitle.'</h2>
                    </div>
                </div>
            </div>';
        }

    I want to insert <img src=”…”> so when I want to edit the section(it’s one page parallax theme)i will be able to add/change an image dynamically.
    I tried <img src=’.$content.’> but it’s not working. Should I add another variable(image) to the function like title and subtitle? of cource i have to customize and the css file properly. but all i see in my page is a broken image, which means that it doesn’t take the parameter value!

    I hope someone could help me!

Viewing 1 replies (of 1 total)
  • The way you have defined the function, $content would be contained between opening and closing tags for the shortcode. So, if the shortcode is [myimage], the value of $content would be whatever is between [myimage] and [/myimage].

    You might have better luck making ‘content’ a variable as you suggested.

Viewing 1 replies (of 1 total)

The topic ‘Customize shortcode function for inserting an image’ is closed to new replies.