• I created a PHP Code Snippet, set it to “Run Everywhere” and activated it.

    I am using Elementor and the respective Elementor theme. For some reason, my snipped does not seem to be called when using Elementor.

    If I copy the code manually in the functions.php of the Elementor theme it works well.

    Any suggestions on what I need to do to get Code Snippets working with Elementor?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    Can you provide the code you are using? There’s nothing in Code Snippets that should prevent the code from running with Elementor.

    Thread Starter crazypatx

    (@crazypatx)

    I trimmed t down to this code, just to test if calling the function work (but it does not)

    function mycustomphpfunction( $record, $handler ) {

    $form_id = $record->get_form_settings( ‘form_id’ );

    if ( $form_id !== ‘myformid’) {

    return;

    }

    echo “<script> console.log(‘Custom PHP function was executed!’); </script>”;

    }

    add_action( ‘elementor_pro/forms/new_record’, ‘mycustomphpfunction’, 10, 2 );

    • This reply was modified 1 year, 8 months ago by crazypatx.
    Plugin Author Shea Bunge

    (@bungeshea)

    Strange, I can’t say for sure why that wouldn’t work. Perhaps try using an anonymous function to prevent name conflicts?

    add_action( 'elementor_pro/forms/new_record', function ( $record, $handler ) {
    	$form_id = $record->get_form_settings( 'form_id' );
    
    	if ( 'myformid' !== $form_id ) {
    		return;
    	}
    
    	echo "<script>console.log( 'Custom PHP function was executed!')</script>";
    
    }, 10, 2 );
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘PHP snippet not recognized by Theme’ is closed to new replies.