Search code examples
phpwordpresspluginsshortcode

Add Function Within Variable String


I am trying to add a function within string to show the output of function via shortcode but it is showing error.

function foo_shortcode($atts, $content = null) { 

$datashortcode = '<div>'

.if(function_exists('rtb_kk'))
{
    rtb_kk();
}. 
'</div>'
;

return $datashortcode; 
}

add_shortcode('showfoo', 'foo_shortcode');

Where i am making mistake?


Solution

  • You have syntax error,

    $datashortcode = '<div>'.(function_exists('rtb_kk') ? rtb_kk() : '').'</div>';
    

    Replace this line.