Using custom JS plugins with WordPress?

Welcome (I’m new myself, too). First and foremost, I highly recommend setting up a Child Theme for your Divi installation; that way any modifications you make won’t be overwritten when Elegant Themes do an update. That said, the best way at this is to use WordPress’ native en queuing system. In your functions.php file, add … Read more

Ajax not working es expected (Returns 0)

Please try this: Add the following in your theme’s functions.php add_action( ‘init’, ‘tnc_aj_scripts’ ); function tnc_aj_scripts() { wp_register_script( “ajax_anmeldung_script”, get_template_directory_uri(). ‘/my-ajax.js’, array(‘jquery’), ‘1.0’, true); wp_localize_script( ‘ajax_anmeldung_script’, ‘mYAjax’, array( ‘ajaxurl’ => admin_url( ‘admin-ajax.php’ ))); wp_enqueue_script( ‘jquery’ ); wp_enqueue_script( ‘ajax_anmeldung_script’ ); } add_action(“wp_ajax_ajax_anmeldung”, “ajax_anmeldung”); add_action(“wp_ajax_nopriv_ajax_anmeldung”, “ajax_anmeldung”); function ajax_anmeldung() { $result[‘one’] = ‘Hey’; $result = json_encode($result); echo $result; … Read more

Button not refreshing page

Because onsubmit event not working with “input” tag. You can see more details in https://www.w3schools.com/jsref/event_onsubmit.asp Supported HTML tags: form, keygen Replace code to <form method=”post” onSubmit=”window.location.reload()”> <input type=”submit” name=”switchlon” id=”switchlon” value=”Switch to London” /><br/> </form> or <form method=”post” > <input type=”submit” name=”switchlon” id=”switchlon” onClick=”window.location.reload()” value=”Switch to London” /><br/> </form>

Base64 & JSON Encode array in PHP, use as HTML data attribute, decode and parse in JavaScript …. with proper Escaping

The possible output of base64_encode() contains a-zA-Z0-9+/ and possibly = or == appended. Testing with $str=”abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=”; we find that: esc_attr( $str ) === $str is true, so it looks like esc_attr() preserves base64 encoded strings. There are possible regexes to help with validation, but according to this answer by @BoltClock, we could check it with … Read more

How Can I Add OnClick Event To A Specific WordPress Menu Link

This is not really a WordPress specific question, but since WordPress does not provide customization for menu items, I think you’re gonna need this. You can use .bind() in jQuery to add an event to user’s click on an specific item. Take a look at this: jQuery(document).ready(function(){ jQuery( “#menu-item-57” ).bind( “click”, function() { goog_report_conversion (‘tel:800-123-4567’); … Read more