How to auto rename JS files to prevent browser cache issues

The function wp_enqueue_script takes a parameter $ver that you can use to automatically add an version parameter to the URL. To always load the newest version of your Javascript-File, you can use the php filemtime-function to give the timestamp of the modification date. In a Plugin, use like this: wp_register_script( ‘my-awesome-script’, plugin_dir_url( __FILE__ ). ‘assets/my-awesome-script.js’, … Read more

How to render HTML content using the Interactivity API?

Rather than binding text with a directive, you could bind a callback with data-wp-watch that sets the inner HTML of the div when it runs: <div data-wp-watch=”callbacks.renderContent”></div> callbacks: { renderContent() { const context = getContext(); const element = getElement(); element.ref.innerHTML = context.randomPost.content.rendered; }, }, Since the callback uses context.randomPost.content.rendered, it should run any time that … Read more

useSelect() plus resolver result is serving cached data incorrectly

Thanks for MVE, @helgatheviking! It was beneficial. When wp.data caches the resolvers, it also considers arguments. Here’s what happens when following the reproduction steps for the bug: Selecting the first product resolves data, creates a cache for getProduct(1), and sets a value for the product state. Selecting second does the same (cache: getProduct(2)) and sets … Read more

How to re-render Gutenberg component when object instance is available

wp_add_inline_script can be used to insert a tiny trigger script that executes after the script specified in script and any instance defined by that script will be available. // When this js executes `Masonry` is sure to be defined wp_add_inline_script( ‘masonry’, ‘if (window.top !== window) doItNow()’); This will end up being executed twice when the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)