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 Answer
1

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' );

Leave a Reply

Your email address will not be published. Required fields are marked *