WordPress.org

Support

Support » Plugins and Hacks » [Resolved] Custom Shortcodes, Includes, and Return.

[Resolved] Custom Shortcodes, Includes, and Return.

  • I was previously using tags to embed videos, and simple conditionals. Users had to fill out a form, which embedded a cookie, and then the videos become available. If the embed-video tag was present, the forms were included. If the cookie was already present, the forms are skipped and the video is included. Now I’d like to upgrade to custom shortcode.

    Here’s what I’ve got so far.

    [Code moderated as per the Forum Rules. Please use the pastebin]

    All of this code works. The issue is that while the video embeds at the proper location within the post, the forms show up at the top of the post no matter what.

    This is because I use return to embed the video and include to embed the forms. There’s lots of conditionals and validation directly within the included forms, so as far as I know, I can’t wrap it all in a variable and return it.

    Is there another way I can continue to use includes, but have the forms show up at the same spot as the video player?

    I hope this makes at least partial sense. Any input is greatly appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
  • No you need to return what needs printing to the screen otherwise you will get exactly what you describe – the form printing before the main content.

    There’s lots of conditionals and validation directly within the included forms,

    then it may need a bit of work to adapt.

    Sorry about the code snippet, just read the rules regarding Code.

    Thanks for the reply. Adaptation it is.

    FYI, I came up with a solution that didn’t require me to rewrite any code. Using:

    ob_start();
    include TEMPLATEPATH . '/assets/inc/forms/basic.php';
    $content = ob_get_clean();
    return $content;

    I was able to assign the included page to a variable. Yeehaw!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Resolved] Custom Shortcodes, Includes, and Return.’ is closed to new replies.
Skip to toolbar