Disable Visible Edit Shortcuts in the Customizer

The simplest way to disable edit shortcuts without unwanted side effects is to no-op override the JS function that generates them in the first place. You can do this from PHP as follows:

add_action( 'wp_enqueue_scripts', function () {
    $js="wp.customize.selectiveRefresh.Partial.prototype.createEditShortcutForPlacement = function() {};";
    wp_add_inline_script( 'customize-selective-refresh', $js );
} );

This will work for any theme.

Leave a Comment