I've added several functions to the functions.php file. I call those functions using a shortcode [shortCode] while in posts, pages, and widgets. But the [shortcode] will not work outside of posts, pages, or widgets. I've tried it in article titles and in other files, but it doesn't work.

I'd like to add a [shortcode] to a function to my tag.php file, but I can't figure it out.


function dynamicContent(){
return 'some dynamic content';
add_shortcode('Dcontent', 'dynamicContent');

How can I get the [Dcontent] shortcode to work in the tag.php file?

  • 2
    But on the php way inside the theme is it better and faster to use the function that works for the shortcode - echo dynamicContent(), not a function for a function, like ? do_shortcode( 'Dcontent' )`. – bueltge Nov 30 '14 at 10:35

Thank you @bueltge for the answer! I was focusing on the shortcode and didn't even think to call the function in the 'normal' way.

echo dynamicContent()


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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