0

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?

2
  • 1
    You simply cannot do that. This is syntax error. Commented Mar 8, 2017 at 12:04
  • so much syntax errors, first read some tutorial about PHP then write a plugin to wordpress :) Commented Mar 8, 2017 at 12:09

1 Answer 1

2

You have syntax error,

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

Replace this line.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for the answer, It worked but now it is showing shortcode content at the top of the page.
So fix its position as per your requirement,. Because you haven't shown any html in your question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.