How to use wp.hooks.addAction() in React JS/Gutenberg?

How to use wp.hooks.addAction? It’s basically like so, just like you’ve attempted: // Hook to the hook_name action. wp.hooks.addAction( ‘hook_name’, ‘namespace’, function(){ console.log( ‘Foo Bar’ ); } ); // Trigger the hook_name action. wp.hooks.doAction( ‘hook_name’ ); Or for hooks which provides one or more parameters to the callback: // Hook to the hook_name action. wp.hooks.addAction( … Read more

How to configure WordPress to be able to use tag inside posts?

Add the following to your theme functions.php: function fb_change_mce_options($initArray) { $ext=”script[charset|defer|language|src|type]”; if ( isset( $initArray[‘extended_valid_elements’] ) ) { $initArray[‘extended_valid_elements’] .= ‘,’ . $ext; } else { $initArray[‘extended_valid_elements’] = $ext; } return $initArray; } add_filter(‘tiny_mce_before_init’, ‘fb_change_mce_options’);

Register and enqueue conditional (browser-specific) javascript files?

WP_Scripts and WP_Styles classes are behind wp_enqueue_script and wp_enqueue_style functions. If you take a look at classes implementation (scripts and styles) then you will see that WP_Scripts class doesn’t support any kind of conditional scripts, but! you can see that WP_Styles does! The problem is that wp_enqueue_style doesn’t allow you to setup condition. So we … Read more

How to add javascript just before the closing body tag in the footer of WordPress

You should always add javascript (and styles) with the WordPress function wp_enqueue_script() Works like this: wp_enqueue_script( $handle // the name of your enqueued file, in your case ‘myscript’ ,$src // source of your file, can be external, or for your example: get_bloginfo(‘template_directory’) . ‘/js/scripts.js’ ,$deps // does your javascript depend on another javascriptfile? for example … Read more

Is it Possible to Extend WP Customize JS Methods?

I will enhance my small comment on your question. But again the hint; I’m not a JS expert. The follow source, hints was only used on playing with the Customizer for different checks, examples, like my sandbox. wp.customize Understanding the WP theme customizer interface centers around understanding the wp.customize javascript object. The wp.customize object is … Read more

Adding javascript to child theme

You should enqueue the script in child theme’s functions.php. for example if name of the js file is custom.js and if you place it under js folder in your child theme, then in functions.php you should add function my_custom_scripts() { wp_enqueue_script( ‘custom-js’, get_stylesheet_directory_uri() . ‘/js/custom.js’, array( ‘jquery’ ),”,true ); } add_action( ‘wp_enqueue_scripts’, ‘my_custom_scripts’ ); Here … Read more