WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Custom Shortcodes, Includes, and Return. (4 posts)

  1. sagalbot
    Member
    Posted 3 years ago #

    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.

  2. elfin
    Moderator
    Posted 3 years ago #

    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.

  3. sagalbot
    Member
    Posted 3 years ago #

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

    Thanks for the reply. Adaptation it is.

  4. sagalbot
    Member
    Posted 3 years ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Topic