wp.editor.initialize does nothing

This was way simpler than I thought it was – even on post.php, you need to run wp_enqueue_editor() before using wp.editor in JavaScript. I had assumed that I wouldn’t need to do that, because an editor was already loaded.

Exclude JS file from 404 error page

There is is_404(). I normally use it to do just the opposite, to add CSS and JS animations which are specific to the 404 error page. In your case that would be: function wpse_339946() { if ( ! is_404() ) { wp_enqueue_script( ‘tracking-js’, get_template_directory_uri() . ‘/js/tracking.js’ ); } } add_action( ‘wp_enqueue_scripts’, ‘wpse_339946’ );

Insert “javascript:void(0);” into URL

I also can’t stand the fact the WordPress removes “javascript:void(0);” from my hrefs (or anything else TBH…) upon saving or using the visual editor. I just started using the Raw HTML plugin that does the job. I enclosed my code in [raw] … [/raw] codes, and did NOT use the visual editor. My “voids” remain … Read more

can a buttongroup have a label?

I have discovered a way of creating a label and a help property for a component that doesn’t have it’s own label or help properties, by wrapping that component in a BaseControl component. Here is my working solution: createElement(PanelRow, {}, createElement(BaseControl, { label: __(‘N element alignment’, ‘my-textdomain’), help: __(‘Set the alignment for n element in … Read more

event/callback on block update?

You might try a useEffect hook subscribed to the attributes.identifier to call the script. something like: function Edit( { attributes, setAttributes } ) { useEffect( () => { // this will fire whenever the attribute changes. thirdPartyScriptFunctionName(); },[attributes.identifier]) const onChangeIdentifier = (value) => { setAttributes({ identifier: value }); }; return ( <div id = {`embed-${ … Read more

Using wp.data.select get actual tags (not id’s) used in post

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 getEntityRecords() with the … Read more

wp-env mysqlcheck error:1130

Step 1: Find the name of your wp-env container First, you need to locate the name of the container created by wp-env. To do this, in the directory of your project containing .wp-env.json, you must run the following command: docker ps This should give you a list of containers. In the Names column, you’ll see … Read more

Adding JavaScript to a WordPress website

Using this link, you will find helpful notes as to how to add a script to your WordPress website. The main idea is to use inbuilt WordPress functions to load your scripts. This is done via the wp_enqueue_script function. Following examples provided in the aforementioned link, you will be able to learn how to enqueue … Read more

Gutenberg add extra attributes to custom format

I was able to add the attribute by passing it in attributes through the registerFormatType settings: attributes: { ‘custom-attr’: ‘custom-attr’ }, then in edit(): toggleFormat( value, { attributes: { ‘custom-attr’: ‘Hello world’ }, } ) I don’t know how exactly it all works together because I could not find detailed explanations in the current documentation. … Read more