0

I am creating plugin that display a quotation From.

public function qt_shortcodez() {

        $QT_Options = get_option("qt_settings");

        $Form = '<table>
                        <tbody>
                            <tr>
                                <td><label>Company Name <span class="text-error">*</span></label></td>
                                <td><input type="text" name="username" id="username" /></td>
                            </tr>
                            <tr>
                                <td><label>Phone <span class="text-error">*</span></label></td>
                                <td><input type="text" name="username" id="phone" /></td>
                            </tr>
                            <tr>
                                <td><label>Email</label></td>
                                <td><input type="text" name="username" id="email" /></td>
                            </tr>
                        </tbody>
                    </table>';

        return $Form;

 }

But it is more bigger form then this($Form), Is there a way to use the template into the shortcodes? Like

public function qt_shortcodez() {

        $QT_Options = get_option("qt_settings");

        // I tried but it is not working :(
        include( sprintf('%s/template/shortcode.php', dirname(__FILE__)) );            
 }
  • How does your shortcode.php look like? Including files within a shortcode function is absolutely possible. And BTW, why do you use sprintf for the include? – tfrommen Feb 13 '14 at 8:47
  • @tf It is just like html and php cobination, but the problem is if someone pass some raw data for the page and then the implemented shortcode, then my form appear on the top of the page area and all the raw data goes after the form :( . I have to return the data so that the form appear on the exact position – jogesh_pi Feb 13 '14 at 8:57
1

I'm not quite sure this is what you are trying to do, however, this is one way to use an external template file for your shortcode output.

This is your shortcode function (e.g., in functions.php):

function qt_shortcodez() {
    return include 'template/shortcode.php';
} // function qt_shortcodez

And that is the very output (i.e., shortcode.php):

<?php
ob_start();
?>
<strong>Hi there!</strong>
<p>
    This is an include test for shortcodes...
</p>
<?php
return ob_get_clean();
  • wow, thanks man. A CUP of Coffee from my side ;) cheers – jogesh_pi Feb 13 '14 at 9:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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