Skip to content

Instantly share code, notes, and snippets.

@timelsass
Created January 14, 2020 05:05
Show Gist options
  • Save timelsass/b709976db58c9f5a6172a5cae5dbbe35 to your computer and use it in GitHub Desktop.
Save timelsass/b709976db58c9f5a6172a5cae5dbbe35 to your computer and use it in GitHub Desktop.
Enables the back to top button in BoldGrid Theme Framework v1 based themes.
<?php
/**
* Plugin Name: BGTFW Back To Top Button
* Description: Enables the back to top button in BoldGrid Theme Framework v1 based themes.
* Plugin URI: https://gist.github.com/timelsass/b709976db58c9f5a6172a5cae5dbbe35
* Author: Tim Elsass
* Author URI: tim.ph
*/
/**
* This will enable the back to top button script and configuration in BGTFW.
*/
add_filter( 'boldgrid_theme_framework_config', function( $configs ) {
$configs['scripts']['options']['goup']['enabled'] = true;
return $configs;
}, 999 );
/**
* This enqueues the goup script. This is only needed because with script debug off the minified
* version of jquery.goup script doesn't exist in BGTFW v1, just the unminified copy. The minified
* version is still attempting to load when the option is enabled via configs so dequeue and enqueue
* the script manually.
*/
add_action( 'wp_enqueue_scripts', function() {
global $boldgrid_theme_framework;
$configs = $boldgrid_theme_framework->get_configs();
wp_dequeue_script( 'boldgrid-goup-js' ); // Minified version doesn't exist in v1 of BGTFW, so dequeue the attempt to enqueue from BGTFW first.
wp_enqueue_script(
'boldgrid-goup-js',
$configs['framework']['js_dir'] . 'goup/jquery.goup.js',
[ 'jquery' ],
$configs['version']
);
$wp_scripts = wp_scripts();
$goup_configs = $configs['scripts']['options']['goup'];
$wp_scripts->add_data( 'boldgrid-goup-js', 'data', sprintf( 'var _goupOptions = %s;', wp_json_encode( $goup_configs ) ) );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment