New answers tagged

0

In my case I had W3 Total Cache installed, and Minify option was set to Manual. After I removed wp-underscore script from manual minify list, issue with the wp.template() Not a function was gone.


3

By default, apiFetch will parse the response for you automatically. You can get the raw response object by setting parse to false in the apiFetch option, e.g.: const handleClick = async () => { try { const result = await apiFetch( { path: '/your/path', parse: false, } ); console.log( result ) // you will ...


1

You should define your btntype attribute as type boolean and set its default to false (maybe better rename it to download then ;). And change it to true when the user selects the download option. If you want to conditionally add the download attribute in your save functions' JSX use this syntax: <a href={ btnurl } className="btn-trigger" ...


0

So meanwhile I have learned some more about React and Gutenberg and the answer was really simple. There are better ways but show and hiding with CSS works. So it's a first step in the right direction I think. get the status of the toggle in the withSelect part of the input field, checkToggle : select( 'core/editor' ).getEditedPostAttribute( 'meta' )[ '...


1

get the automatically generated excerpt The REST API always includes the auto-generated excerpt by default, so try with getEntityRecord() like so: Note though, if the user edited the actual excerpt (i.e. the "Excerpt" panel in the Settings sidebar and not your metaExcerpt value), then the currentExcerpt would also use the excerpt the user has just ...


0

You can trigger a JavaScript function that moves the popup when the window size changes. <body onresize="movePopup()"> <script> function movePopup() { // move your popup } </script> </body>


0

Ok, problem came from Autoptimize problem : there's an option, Also aggregate inline JS? , should be unchecked There must be a way to exclude GTM script from Autoptimize, still haven't take a look yet !


1

You can use getEntityRecord() like so: const tag_ids = wp.data.select( 'core/editor' ).getEditedPostAttribute( 'tags' ); // the last parameter is always the tag ID (and just one single ID) const tag = wp.data.select( 'core' ).getEntityRecord( 'taxonomy', 'post_tag', tag_ids[0] ); console.log( tag ? tag.name : 'still resolving or no such tag..' ); Or use ...


0

On the post edit screens when Gutenberg is enabled, you may use a JS variable set by the wp.media object. wp.media.view.settings.post.id, On the front end, the best approach was already outlined above.


2

Using woocommerce woocommerce_add_to_cart_fragments filter you can do that. Going by the id attribute that you currently have for the span that displays the cart total, you can use the following code add_filter('woocommerce_add_to_cart_fragments', 'bt_update_cart_total'); function bt_update_cart_total ($fragments) { $fragments['#order-total-price'] = '&...


1

I got here debugging the same error on my WP installation. The previous answer was for developer of plugin/theme, so being an admin, I needed a little different approach. I had to find the source of the problem myself. As I learned here I used following line in my config.php to get unminified version of Javascript sources. define('SCRIPT_DEBUG', true); TL;...


2

You're not supposed to make HTTP requests etc directly inside React components, you need to use useEffect. A react component needs to run as quickly as possible, even if work that needs doing isn't finished yet. By using useEffect you tell React to run a separate function after rendering is complete, giving you the opportunity to make requests and for your ...


1

To answer your broader question about resources - while there are many articles out there, I would always recommend checking out the official WordPress API Handbook first. You first have to decide which JavaScript library you want to use to make HTTP requests to access the REST API. Axios is one example. To set the featured image, you first have to uploaded ...


0

After some time reading the Editor Documentation I found the proper solution. This is how you can listen to changes and get the id of the Parent Combobox select in the WP Editor: wp.data.subscribe( function () { var newParent = wp.data.select('core/editor').getEditedPostAttribute('parent'); console.log(newParent); } ); wp.data.subscribe is called every ...


Top 50 recent answers are included