2

when I am using this document on web server it is running ok but when this file is running to use the plugin in WordPress then I have to put the shortcode of the file on the page on which I want to apply effect of that plugin.... but when I am putting the shortcode then it only shows the string of that shortcode, not the effect. plz find the below coded file and provide a solution.

<?php
function sac_form()
{
echo "<html>";
echo "<head></head>";
echo "<body>";
echo "<form>";
echo "<table>";
echo '<tr><td>Name</td><td><input type="text" name="Name"></td></tr>';
echo '<tr><td>Email</td><td><input type="text" name="Email"></td></tr>';
echo '<tr><td>Subject</td><td><input type="text" name="subject"></td></tr>';
echo '<tr><td>Message</td><td><textarea rows="4" cols="50"></textarea></td></tr>';
echo '<tr><td><input type="submit" name="submit" value="Submit"></td></tr>';
echo "</table>
</form>
</body>
</html>";
}
add_shortcode( 'short_code', 'sac_form' );
?>
1
  • At first, you should describe how you use it and which shortcode do you use in the content. at second, the function sac_form should return the markup and content, not echo! Write all this html in a variable and return it. See also the codex for helpful hints and examples.
    – bueltge
    Commented Jun 14, 2017 at 11:04

1 Answer 1

2

The shortcodes only run if they are used in the WordPress environment. It appears you are using the shortcode in a page that the WordPress's engine has not been loaded.

Also, always store your data in a variable and then return the value instead of using echo:

function sac_form() {
    $data = '
    <html>
        <head></head>
        <body>
            <form>
                <table>
                    <tr><td>Name</td><td><input type="text" name="Name"></td></tr>
                    <tr><td>Email</td><td><input type="text" name="Email"></td></tr>
                    <tr><td>Subject</td><td><input type="text" name="subject"></td></tr>
                    <tr><td>Message</td><td><textarea rows="4" cols="50"></textarea></td></tr>
                    <tr><td><input type="submit" name="submit" value="Submit"></td></tr>
                </table>
            </form>
        </body>
    </html>';
    return $data;
}
add_shortcode( 'short_code', 'sac_form' );

Not the answer you're looking for? Browse other questions tagged or ask your own question.