Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have this part of code:

return '<img class="myimage '.$text_color.' '.$horizontal.$slide_fitscreen.'" src="'.$image.'" alt="" '.$slide_desc.' />';

What I want to do is to return also a php shortcode but not inside the img element, because my shortcode generates a a element so I need to return it after the img

this is my shortcode:

<?php echo do_shortcode('[daisy]'); ?>

I've tried this:

return '<img class="myimage '.$text_color.' '.$horizontal.$slide_fitscreen.'" src="'.$image.'" alt="" '.$slide_desc.' />'.do_shortcode('[daisy]');

but is not working, I receive:

Error (Parseerror): Syntax Error Unexpected Token <

How can I make this ? Thanks! Later edit: here is the entire script:

<?php 
function custom_slidessc($atts, $content = null) {

$user_agent = $_SERVER["HTTP_USER_AGENT"];
if(strpos($user_agent,'iPhone') || strpos($user_agent,'iPod') || strpos($user_agent,'Android')){ $mobile = true; }else{ $mobile = false; }
$ipad = strpos($user_agent, 'iPad') ? true : false;

$class = shortcode_atts( array('text_color' => '#ffffff', 'image' => '', 'video_vimeo' => '', 'video_youtube' => '', 'video_mp4' => '', 'video_ogg' => '', 'video_webm' => '', 'video_poster' => '', 'slide_desc' => '', 'slide_horizontal' => '', 'slide_fitscreen' => '', 'slide_noresize' => ''), $atts );

    /* Slide Description */
    if($class['slide_desc'] != ''){ 
        $slide_desc = $class['slide_desc']; 
        $slide_desc = "title=\"".$slide_desc."\"";
    }

    /* Slide Text/Cursor Color */
    if($class['text_color'] == '#ffffff'){
        $text_color = 'text_white'; 
    }else{
        $text_color = 'text_black'; 
    }

    /* ------------------------------------*/
    /* -------->>> IMAGE SLIDE <<<---------*/
    /* ------------------------------------*/
    if($class['image'] != ''){
        $image = $class['image'];
        if($class['slide_horizontal'] == 'true'){ $horizontal = 'slide_horizontal '; }else{ $horizontal = ''; }
        if($class['slide_horizontal'] == 'true' || $class['slide_fitscreen'] == 'true'){ $slide_fitscreen = 'slide_fitscreen'; }else{ $slide_fitscreen = ''; }
        return '<img class="myimage '.$text_color.' '.$horizontal.$slide_fitscreen.'" src="'.$image.'" alt="" '.$slide_desc.' />';

    /* ------------------------------------*/
    /* ----->>> HTML5 VIDEO SLIDE <<<------*/
    /* ------------------------------------*/
    }elseif(($class['video_mp4'] != '' or $class['video_ogg'] != '' or $class['video_webm'] != '') AND !$mobile){
        $video_mp4 = $class['video_mp4'];
        $video_ogg = $class['video_ogg'];
        $video_webm = $class['video_webm'];
        if($class['video_poster'] != ''){ $video_poster = "poster=\"".$class['video_poster']."\""; }else{ $video_poster = ""; }
        return '<div class="myimage myvideo '.$text_color.'" '.$slide_desc.'>'.do_shortcode('[video mp4="'.$video_mp4.'" ogg="'.$video_ogg.'" webm="'.$video_webm.'" '.$video_poster.' preload="true"]').'</div>';

    /* ------------------------------------*/
    /* ------->>> YOUTUBE SLIDE <<<--------*/
    /* ------------------------------------*/
    }elseif($class['video_youtube'] != ''){
        $video_youtube = $class['video_youtube'];
        if($class['slide_noresize'] = 'true'){ $video_noresize = 'height="360" width="640"'; }else{ $video_noresize = 'height="100%" width="100%"'; }

        $strText = preg_replace( '/(http|ftp)+(s)?:(\/\/)((\w|\.)+)(\/)?(\S+)?/i', 'link', $video_youtube );
        if($strText == 'link'){
            $array_link_explode = explode('v=', $video_youtube); 
            $array_link_explode = explode('&', $array_link_explode[1]); 
            $video_youtube =$array_link_explode[0];
        }
        $video_poster = $class['video_poster'];

        if($mobile){
            return '<div class="myimage myvideo myvideo_yt '.$text_color.'"  '.$slide_desc.'><div style="height: 100%; width: auto; margin: 0 auto; position: relative;"><iframe style="bottom: 0; margin: auto; position: absolute; top: 0; z-index: 9999999999;" type="text/html" '.$video_noresize.' src="http://www.youtube.com/embed/'.$video_youtube.'?wmode=opaque" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></div><img src="'.$video_poster.'" alt="" style="position:absolute;" /></div>';
        }else if($ipad){
            if($video_poster){ $ipad_poster = '<img src="'.$video_poster.'" alt="" style="position:absolute;" />'; }else{ $ipad_poster = ''; }
            return '<div class="myimage myvideo myvideo_yt '.$text_color.'"  '.$slide_desc.' style="height: 100%;"><div style="height: 100%; width: 640px; margin: 0 auto; position: relative;"><iframe class="youtube-player" style="position:absolute;top:0;bottom:0;margin:auto;z-index: 77777777;" type="text/html" '.$video_noresize.' src="http://www.youtube.com/embed/'.$video_youtube.'?wmode=opaque" frameborder="0"></iframe></div>'.$ipad_poster.'</div>';
        }else if($video_poster != ''){
            return '<div class="myimage myvideo myvideo_yt '.$text_color.'"  '.$slide_desc.' style="height: 100%;"><div style="height: 100%; width: 640px; margin: 0 auto; position: relative;"><iframe class="youtube-player" style="position:absolute;top:0;bottom:0;margin:auto;z-index: 77777777;" type="text/html" '.$video_noresize.' src="http://www.youtube.com/embed/'.$video_youtube.'?wmode=opaque" frameborder="0"></iframe></div><img src="'.$video_poster.'" alt="" style="position:absolute;" /></div>';
        }else if(!$ipad){ //disable fullscreen for ipad
            return '<div class="myimage myvideo myvideo_yt '.$text_color.'" '.$slide_desc.'><iframe class="youtube-player" type="text/html" width="100%" height="100%" src="http://www.youtube.com/embed/'.$video_youtube.'?wmode=opaque" frameborder="0"></iframe></div>';
        }

    /* ------------------------------------*/
    /* -------->>> VIMEO SLIDE <<<---------*/
    /* ------------------------------------*/
    }elseif($class['video_vimeo'] != ''){
        $video_vimeo = $class['video_vimeo'];
        if($class['slide_noresize'] = 'true'){ $video_noresize = 'height="360" width="640"'; }else{ $video_noresize = 'height="100%" width="100%"'; }

        $strText = preg_replace( '/(http|ftp)+(s)?:(\/\/)((\w|\.)+)(\/)?(\S+)?/i', 'link', $video_vimeo );
        if($strText == 'link'){ 
            $array_link_explode = explode('.com/', $video_vimeo); 
            $video_vimeo = $array_link_explode[1]; 
        }
        $video_poster = $class['video_poster'];

        if($mobile){
            return '<div class="myimage myvideo myvideo_yt '.$text_color.'"  '.$slide_desc.'><div style="height: 100%; width: auto; margin: 0 auto; position: relative;"><iframe style="bottom: 0; margin: auto; position: absolute; top: 0; z-index: 9999999999;" src="http://player.vimeo.com/video/'.$video_vimeo.'?title=0&amp;byline=0&amp;portrait=0&amp;color=ffffff" '.$video_noresize.' frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></div><img src="'.$video_poster.'" alt="" style="position:absolute;" /></div>';
        }else if($ipad){
            return '<div class="myimage myvideo myvideo_yt '.$text_color.'"  '.$slide_desc.' style="height: 100%;"><div style="height: 100%; width: 640px; margin: 0 auto; position: relative;"><iframe style="bottom: 0; margin: auto; position: absolute; top: 0; z-index: 77777777;" src="http://player.vimeo.com/video/'.$video_vimeo.'?title=0&amp;byline=0&amp;portrait=0&amp;color=ffffff" '.$video_noresize.' frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></div><img src="'.$video_poster.'" alt="" style="position:absolute;" /></div>';
        }else if($video_poster != ''){
            return '<div class="myimage myvideo myvideo_yt '.$text_color.'"  '.$slide_desc.' style="height: 100%;"><div style="height: 100%; width: 640px; margin: 0 auto; position: relative;"><iframe style="bottom: 0; margin: auto; position: absolute; top: 0; z-index: 77777777;" src="http://player.vimeo.com/video/'.$video_vimeo.'?title=0&amp;byline=0&amp;portrait=0&amp;color=ffffff" '.$video_noresize.' frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></div><img src="'.$video_poster.'" alt="" style="position:absolute;" /></div>';
        }else if(!$ipad){ //disable fullscreen for ipad
            return '<div class="myimage myvideo myvideo_yt '.$text_color.'" '.$slide_desc.'><iframe src="http://player.vimeo.com/video/'.$video_vimeo.'?title=0&amp;byline=0&amp;portrait=0&amp;color=ffffff" width="100%" height="100%" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></div>';
        }
    }else{
        return false;
    }
}
add_shortcode("slide", "custom_slidessc");
?>
share|improve this question
    
Can we see your entire (relevant) code? –  Chip Bennett Aug 27 '12 at 16:50
    
At a quick review, there is an issue at line 64 of this code sample ... er, my bad, mixed it up in another test environment. Disregard this. –  Edward Caissie Aug 27 '12 at 18:44

2 Answers 2

up vote 0 down vote accepted

Do not call do_shortcode(). Use the associated handler instead.

And if you want to call the shortcode without parameters you have to make the parameters optional in the handler’s declaration:

function custom_slidessc($atts = array(), $content = null)

So what you need is:

return '<img>' . custom_slidessc();
share|improve this answer
    
Sorry, I'm confused where should I add the shortcode exactly? –  agis Aug 28 '12 at 23:45
    
Where you declare the function is up to you. –  toscho Aug 28 '12 at 23:48

'do_shortcode' needs to be echoed for its output to be printed to the screen, so you will need to find a way to work around that. Here is an idea:

/** Start an output buffer to capture the echo */
ob_start()
echo do_shortcode( '[daisy]' );
/** Put the output into a usable variable */
$daisy_output = ob_get_contents();
/** End the output buffer capture */
ob_end_clean();

return '<img class="myimage ' . $text_color . ' ' . $horizontal . $slide_fitscreen . '" src="' . $image . '" alt="" ' . $slide_desc . ' />' . $daisy_output;

There may be a better method but at least this should provide a proof-of-concept for the output you are trying to get.

share|improve this answer
    
Unfortunately is not working for me, is very annoying for me because I have the impression that is something simple but my experience with php is basic. However if you want to take a look at the entire script here is a fiddle –  agis Aug 27 '12 at 17:29
    
I've updated my post with the entire script –  agis Aug 27 '12 at 17:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.