WordPress.org

Ready to get started?Download WordPress

Forums

Including a file via shortcode API (2 posts)

  1. Rebecca Schaefer
    Member
    Posted 2 years ago #

    I'm trying to include an external file via a shortcode without using ob_clean, etc. Presently, I have a function that includes the file, which was working on its own, but when I run it through the shortcode API it simply returns true.

    Any [simple] way to hack around this?

  2. fireproofsocks
    Member
    Posted 2 years ago #

    Can you paste the key parts of your code? Sometimes manipulating the output buffer (ob) is the only way to make that stuff work, e.g.

    ob_start();
    include $filename;
    return ob_get_clean();

    Remember that functions called by shortcode should return data, not print it. WP has a bad habit of blurring the two, and the over-reliance on printing has severe architectural limitations, imo. So maybe your file is printing data, and remember that print is actually a function, so it does RETURN a value... it returns TRUE if it printed successfully.

Topic Closed

This topic has been closed to new replies.

About this Topic