Last active
April 20, 2021 12:37
-
-
Save geckoseo/b9685761f3eb5aa40fff0186fd2d31d9 to your computer and use it in GitHub Desktop.
Toggle Outline of Containers while in Beaver Builder editor with a keyboard shortcut
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 | |
/** | |
* Create Builder Shortcut to highlight containers | |
*/ | |
add_filter( 'fl_builder_keyboard_shortcuts', function( $shortcuts ) { | |
$shortcuts['outlineObjects'] = array( | |
'label' => __( 'Outline Objects'), | |
'keyCode' => 'mod+q' //shortcut is Ctrl+q or Cmd+q - Change this to anything that works best for you | |
); | |
return $shortcuts; | |
}); | |
function outline_Objects() { | |
// Check if Beaver Builder is active | |
if ( class_exists('FLBuilderModel') && FLBuilderModel::is_builder_active() ) { | |
/** | |
* Enqueue your custom JavaScript file | |
* | |
************************************* | |
* See "shortcut-script.js" file below | |
************************************* | |
* | |
* Be sure to use the appropriate url path depending on if your | |
* code is contained in a custom plugin or child theme. | |
* | |
*/ | |
wp_enqueue_script('outlineObjects', get_stylesheet_directory_uri() . '/js/shortcut-script.js'); | |
} | |
} | |
add_action('wp_enqueue_scripts','outline_Objects'); |
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($) { | |
// Create a function to fire when your custom shortcut is triggered | |
function outlineObjects() { | |
$('.fl-col').toggleClass('fl-col-highlight'); | |
$('.fl-row-content-wrap').toggleClass('fl-row-highlight'); | |
} | |
$(function() { // Once the document is ready | |
// Register a hook listener using the key that you registered | |
// your shortcut with along with the function it should fire. | |
FLBuilder.addHook('outlineObjects', outlineObjects ); | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reference link for the Beaver Builder shortcuts API:
https://docs.wpbeaverbuilder.com/beaver-builder/developer/tutorials-guides/customize-keyboard-shortcuts/