Last active
April 22, 2019 19:50
-
-
Save alexmustin/fc7f16543a5242a6e22863dbd9562ac1 to your computer and use it in GitHub Desktop.
Gutenberg - make Button blocks open links in a new window
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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 ); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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