0

I have saved my file contact.php into server and am making amp page of contact form

    <div>
        <?php echo do_shortcode( '[contact-form-7 id="4" title="Contact form 1 col FR"]' ); ?>
    </div>

using this code i goot an error like this:

--> Undefined function 'do_shortcode'.

How can I avoid this error?

1
  • Is contact.php a template or it's an separate file? If it's separate file then you need to include wp-load.php from root wordpress folder before calling this function. May 22, 2021 at 7:35

1 Answer 1

0

The function do_shortcode is only available when a file is executed in wordpress-context. So if contact.php is called directly, ensure to add a include('wp-load.php'); at the beginning of the contact.php.

The file wp-load.php is placed on the same level as wp-config.php, so depending on the file-location of your contact.php you need to change the path for example to something like this: include(__DIR__ . '/../../wp-load.php');

2
  • Thank's ! This file is not a part of wordpress, because this is simple html file has saved into contact.php then how to get shortcode data into html page . May 23, 2021 at 12:33
  • 1
    That's not going to work in any reasonable way. To use WordPress plugin shortcodes, you're going to want to use WordPress. Make that HTML page into a page template or something similar and life will be far easier. May 24, 2021 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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