Shortcodes Pro
Why can't I echo or print? (5 posts)

  1. AsraiLight
    Posted 2 years ago #

    I've created shortcodes that print variable content on the screen. The only way I've been able to get the content to show up is to use return (i.e. return 'Hello World!';). Neither echo nor print works, even for something simple.

    Return works to a point, but I can only use it once within the shortcode, which doesn't work if I need to add code between. Is there a way I can use echo or print? Am I missing something?


  2. AsraiLight
    Posted 2 years ago #

    Just for arguments sake, I've also tried assigning this content to variables and outputting the variables in a return string. It doesn't work. Here's the code:

    if (array_key_exists('logo-file', $_GET))
    $logo-file = '<img style="max-height: 75px;" src="/assets/' . strip_tags( stripslashes( $_GET['logo-file'] ) ) . '" alt="" />';
    return $logo-file;
  3. AsraiLight
    Posted 2 years ago #

    Figured out this particular problem...the dashes in my variables were causing the issue. (Which is odd, because I've seen others use code with dashes in their variable. Must be bad syntax.)

    Anyway, it would still be nice to be able to echo or print with this. Is it just not possible with shortcodes? A limitation of the WordPress code, perhaps?

  4. esmi
    Forum Moderator
    Posted 2 years ago #

    You should never use hyphens in PHP generally. Stick to underscores.

  5. UaMV
    Posted 2 years ago #

    @AsraiLight: Yup, shortcodes require a return value. Check out this in the Codex.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Shortcodes Pro
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.