Skip to content

Instantly share code, notes, and snippets.

@geckoseo
Last active April 20, 2021 12:37
Show Gist options
  • Save geckoseo/b9685761f3eb5aa40fff0186fd2d31d9 to your computer and use it in GitHub Desktop.
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
<?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');
(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);
@geckoseo
Copy link
Author

geckoseo commented Sep 5, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment