Skip to content

Instantly share code, notes, and snippets.

@alexmustin
Last active April 22, 2019 19:50
Show Gist options
  • Select an option

  • Save alexmustin/fc7f16543a5242a6e22863dbd9562ac1 to your computer and use it in GitHub Desktop.

Select an option

Save alexmustin/fc7f16543a5242a6e22863dbd9562ac1 to your computer and use it in GitHub Desktop.
Gutenberg - make Button blocks open links in a new window
<?php
//* Enqueue Script
add_action( 'wp_enqueue_scripts', 'yourtheme_enqueue_globaljs_script' );
function yourtheme_enqueue_globaljs_script() {
wp_enqueue_script( 'global-js', get_stylesheet_directory_uri() . "/global.js", array( 'jquery' ), '1.0', true );
}
(function($) {
'use strict';
// In the Gutenberg editor, give your button block an Additional CSS Class of: target-blank
// Make Gutenberg button blocks with a custom class open links in a new window
$('.wp-block-button.target-blank > a').attr('target','_blank');
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment