Unable to register a block using block.json in Block Editor

The section titled Live rendering in the block editor on the WordPress documentation page, Creating dynamic blocks, has sample code demonstrating how to use server-side rendering. The documentation page says: Gutenberg 2.8 added the <ServerSideRender> block which enables rendering to take place on the server using PHP rather than in JavaScript. Rather than setting edit: … Read more

Why do WordPress adds the id=”handle-{js|css}” attribute to scripts and stylesheet?

The id attribute was added to the <style> tags in WordPress v4.1 (2014) — see the Trac changesets 29956 and 29958 which both mentioned ticket #30032 (“Add ID attribute to style element from wp_add_inline_style()“): In order to support partial preview refreshes (#27355), it is important for all partials being updated to have an element with … Read more

Trying to use wp_register_script/style and enqueu them from an array – getting an error [duplicate]

As the “Error Message” (which is in fact a “doing it wrong”-message) is telling you, you’re using the wrong hook: Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or login_enqueue_scripts hooks. Just read about hooks, wrap your code in a callback and then register it properly on one of the … Read more

wp_register_script and wp_register_style when shortcode is used

Your scripts and styles all share the same handle, “fancybox”, which should be unique, and I think that’s your issue. Try this: wp_register_script( ‘mousewheel’, get_stylesheet_directory_uri(‘/js/jquery.mousewheel-3.0.6.pack.js’, __FILE__), array(‘jquery’), ‘3.06’, true ); wp_register_script( ‘fancybox-script’, get_stylesheet_directory_uri(‘/js/jquery.fancybox.js’, __FILE__), array(‘jquery’), ‘1.0’, true ); wp_register_script( ‘fancybox-pack’, get_stylesheet_directory_uri(‘/js/jquery.fancybox.pack.js’, __FILE__), array(‘jquery’), ‘1.0’, true ); wp_register_script( ‘fancybox-buttons’, get_stylesheet_directory_uri(‘/js/jquery.fancybox-buttons.js’, __FILE__), array(‘jquery’), ‘1.0’, true ); wp_register_script( … Read more

Enqueue scripts in the footer

From http://codex.wordpress.org/Function_Reference/wp_register_script: <?php wp_register_script( $handle, $src, $deps, $ver, $in_footer ); ?> This means you need to add the $deps and $ver values to wp_register_script() in order to set $in_footer. Like this: wp_register_script( ‘justifiedGallery’, plugins_url(‘js/jquery.justifiedGallery.min.js’, __FILE__), false, // or array(), or array(‘jquery’) if this depends on jQuery ‘1.0’, // or your plugin version, or the version … Read more

JavaScript file successfully registered but does not render correctly

You were using action to enqueue script, instead you need to use filter hook. As, you are adding a new script to the scripts call. However, if you used action hook for the wp_head call it works there. <?php add_filter(‘wp_enqueue_scripts’, ‘colorboxJS’); function colorboxJS() { wp_enqueue_script( ‘colorbox’, get_stylesheet_directory_uri() . ‘/colorboxJSfile.js’, array(‘jquery’) ); } ?>