0

I am using cf7 form in wordpress admin panel: enter image description here

On front end its working fine but I need in admin panel. I have tried below code in functions.php but it did not work:

add_filter( 'wpcf7_load_js', '__return_false' );
add_filter( 'wpcf7_load_css', '__return_false' );

function cf7_script_and_style() {
   // add here the logic to return if this isn't the contact page
   if ( function_exists( 'wpcf7_enqueue_scripts' ) ) wpcf7_enqueue_scripts();
   if ( function_exists( 'wpcf7_enqueue_styles' ) ) wpcf7_enqueue_styles();
}
add_action( 'wp_enqueue_scripts', 'cf7_script_and_style' ); //or wp_footer or wp_body_open etc

When I submit it, it just reload the page, No email is received. Ajax is also disabled so I believe scripts are not loaded in admin panel. What is your suggestions on it. How can I fix it?

1 Answer 1

0

The action wp_enqueue_scripts action hook is only on the frontend: try changing this to admin_enqueue_scripts for the admin (untested):

add_action( 'admin_enqueue_scripts', 'cf7_script_and_style' );

Edit:

After looking at the definition for wpcf7_enqueue_scripts(), it turns out that CF7 doesn't anticipate being loaded in the admin: who would've guessed. You'll need to copy a lot of that file and adjust it to work in the admin (using admin_enqueue_scripts instead of wp_enqueue_scripts).

3
  • I tried admin_enqueue_scripts but still same issue. nothing changed :( Jun 14, 2023 at 3:50
  • Took a look at the source code and updated my answer.
    – Caleb
    Jun 14, 2023 at 4:01
  • 1
    okay I will have to make custom form then Jun 14, 2023 at 15:24

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.