Shortcode outputs at top of post
-
The shortcode currently outputs at the top of the page or post rather than in the place that it is called. Shortcode functions should return a string with the HTML that should be placed in the page rather than outputting immediately. This should either be corrected by constructing a string variable or by using an output buffer as with the patched function example given here:
/* print_glossary_list () * * create a table, load with acronym output, and return html code */ function print_glossary_list() { $domain = Acronym_Manager::get_textdomain(); // Sort the acronyms appropriately $acronyms = get_option('acronym_acronyms'); uksort($acronyms, "strnatcasecmp"); // Start the output buffer ob_start(); // Output the acronyms table ?> <table border="0"> <?php foreach ($acronyms as $acronym => $fulltext) { ?> <tr><td><strong> <?php echo $acronym; ?> </strong></td><td> <?php echo $fulltext; ?> </td></tr> <?php } ?> </table> <?php // Return the contents of the output buffer return ob_get_clean(); }
Output buffering might not be the best way to do this as it can have problems, but for me was quick and easy to get the plugin working the way it should.
- The topic ‘Shortcode outputs at top of post’ is closed to new replies.