How do I add a javascript file to all admin pages via a plugin?

The Plugin Developer Handbook recommends using plugins_url() to create the URL to the JS file. Try using that function inside your script loader, and using a different handle for the script depending on the context (like prefixing the admin script name with “admin-“) to avoid conflicting script registration. Alternatively, you can register the script just … Read more

WordPress AJAX Call Not Return Result

There’s two problems: You’re not sending the AJAX request to the correct URL. You’re using PHP-style concatenation instead of JavaScript. For the first issue, a relative URL “admin-ajax.php” is not going to work. If you are on a page like /about-us/ then jQuery is going to send the request to /about-us/admin-ajax.php, which doesn’t exist. The … Read more

Gutenberg RichText

Please paste the full code, According to official Gutenberg button block. You need to have additional block attributes to use for button link,text – https://github.com/WordPress/gutenberg/blob/master/packages/block-library/src/button/index.js <RichText.Content tagName=”a” className={ linkClass } href={ url } title={ title } style={ buttonStyle } value={ text } /> As you can see, there’s a URL, Title & Text attributes. url: … Read more

Collapsible button inside a ul list does work in jsfiddle but not in WP

Solution provided by Steven <script type=”text/javascript”> ( function() { coll = document.getElementsByClassName(“col”); conn = document.getElementsByClassName(“con”); var i; for (i = 0; i < coll.length; i++) { coll[i].setAttribute(‘data-id’, ‘con’ + i); conn[i].setAttribute(‘id’, ‘con’ + i); coll[i].addEventListener(“click”, function() { this.classList.toggle(“active”); var content = document.getElementById(this.getAttribute(‘data-id’)); if (content.style.maxHeight) { content.style.maxHeight = null; } else { content.style.maxHeight = content.scrollHeight + … Read more

Create custom blocks for bootstrap

Rather than create new blocks to represent the Bootstrap classes. You should enqueue the bootstrap js and css files in your theme as you say you normally do. Once bootstrap has been added to the theme, you can simply assign the bootstrap css classes to the already existing Gutenberg blocks. As demonstrated in the following … Read more