How to get value of selected page template in Gutenberg editor?

I slightly modified SkyShab’s code, because it fired template change event on page load and it didn’t fire when template was changed to default (since getEditedPostAttribute( ‘template’ ) is then ”, which equals to null when testing for template change) const { select, subscribe } = wp.data; class PageTemplateSwitcher { constructor() { this.template = null; … Read more

Why is my Gutenberg block returning an error after initial save?

The main issue in your code is with these two attributes which use the exact same selector (the first span element in your block content): checkListItemOne: { type: ‘string’, source: ‘html’, selector: ‘span’ // same as below }, checkListItemTwo: { type: ‘string’, source: ‘html’, selector: ‘span’ // same as above } Which means the block … Read more

WordPress Jquery Fade in, Fade out effect

Going through your source – jQuery Source – it seeems that noConflict() is getting called right at the end. To fix your hover.js then would look something like this: jQuery(function($) { //Allow the use of $ namespace in this function. // OPACITY OF BUTTON SET TO 50% $(“.imgopacity”).css(“opacity”,”0.5″); // ON MOUSE OVER $(“.imgopacity”).hover(function () { … Read more

wp.template() Not a function

Ah, I get it. When you enqueue your admin script, add ‘wp-util’ as a dependancy. wp_enqueue_script( ‘script_handle’, plugin_dir_url( __FILE__ ) . ‘script.js’, array( ‘jquery’, ‘wp-util’ ), ‘1.0’, true );

Question about the way that wp_register_script works

For the record this entirely the wrong thing to do. Themes should avoid (read never!) de-register the WordPress registered jQuery scripts (plug-ins should absolutely never do this). If a theme is to de-register the jquery script (to replace it) then it should re-register it properly: wp_register_script( ‘jquery’, ‘http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js’); Here-in lies the problem. The above is … Read more

jQuery Tree View and wp_list_pages

EDIT: After chatting with AlxVallejo, we came to a solution. Here’s what we talked about: You were not properly using the wp_enqueue_scripts hook and the functions that go along with it, as I informed you these hooks and actions need to be done in functions.php. You also discovered yourself that you were not initializing the … Read more

How to localized one js file for different actions?

Maybe I got your question wrong. I don’t get what you mean by: If I don’t do the localize, I can’t get response. But in general, this function lets you localize your JS strings, but you can also use it to set JS variables: function set_my_js_var() { // logic here for setting the right JS … Read more