• Hi, your plugin is almost what I am looking for!
    Would it be too hard to add some functionality for creating Global attributes for blocks that will be used in ALL posts without recreating the same attribute by hand for each new block?
    Example:
    For Pinterest, all images should have [data-pin-description=””] and [data-pin-title=””] attributes, or in many cases other attributes are used very frequently (id, rel, etc.)

    Please, let me know if it’s something that can be done by users like myself (I have a medium-level experience with PHP,JS but an absolute zero in WP programming.

    Thank you!!!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author websevendev

    (@websevendev)

    It’s technically possible, but probably too complex/nuanced.

    This will add the data-pin-description and data-pin-title values for core/image blocks by default.

    add_action('enqueue_block_editor_assets', function() {
    	$js = <<<JS
    wp.hooks.addFilter('blocks.registerBlockType', 'attributes-for-blocks/defaults', settings => {
    	if(settings.name === 'core/image') {
    		return {
    			...settings,
    			attributes: {
    				...settings.attributes,
    				attributesForBlocks: {
    					...settings.attributesForBlocks,
    					default: {
    						'data-pin-description': '',
    						'data-pin-title': '',
    					},
    				},
    			}
    		}
    	}
    	return settings
    });
    JS;
    	wp_add_inline_script('attributes-for-blocks', $js);
    });

    It will invalidate any existing blocks that don’t have custom attributes as it now has a different default value.

    Thread Starter axa222

    (@axa222)

    Thank you for answering so fast!
    Please, forgive me but I don’t understand where exactly should your code go.
    I mean, should it be added to one of your existing plugin files or to one of the core WP files?
    Thank you!

    Thread Starter axa222

    (@axa222)

    Got it working! Thanks!!!!

    Thread Starter axa222

    (@axa222)

    Is it possible to add these attributes to the IMG tags – your suggested code adds attributes to FIGURE tags.

    Thank you!

    • This reply was modified 2 years, 4 months ago by axa222.
    Plugin Author websevendev

    (@websevendev)

    should it be added to one of your existing plugin files or to one of the core WP files

    Your child theme’s functions.php is the preferred location. If you add to plugin or WP core files the changes get overwritten on updates.

    Is it possible to add these attributes to the IMG tags – your suggested code adds attributes to FIGURE tags

    No, the plugin can only add attributes to the root element blocks.

    I may add these features you’re looking for in the future, but currently I don’t have the time as I’m working on something else, sorry.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Global settings?’ is closed to new replies.