Skip to content

Commit f37d335

Browse files
authored
Merge pull request #2626 from skaut/register-script-in-init
Registering shortcode scripts and styles in the init hook instead of the wp_enqueue_scripts hook
2 parents d83814a + 35cc80b commit f37d335

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

src/php/frontend/class-shortcode.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,15 @@ final class Shortcode {
3232
* Registers all the hooks for the shortcode.
3333
*/
3434
public function __construct() {
35-
add_action( 'init', array( self::class, 'add' ) );
36-
add_action( 'wp_enqueue_scripts', array( self::class, 'register_scripts_styles' ) );
35+
add_action( 'init', array( self::class, 'init' ) );
3736
}
3837

3938
/**
40-
* Adds the shortcode to WordPress.
39+
* Registers all the scripts and styles used by the shortcode and adds the shortcode.
4140
*
4241
* @return void
4342
*/
44-
public static function add() {
45-
add_shortcode( 'sgdg', array( self::class, 'render' ) );
46-
}
47-
48-
/**
49-
* Registers all the scripts and styles used by the shortcode.
50-
*
51-
* @return void
52-
*/
53-
public static function register_scripts_styles() {
43+
public static function init() {
5444
Script_And_Style_Helpers::register_script(
5545
'sgdg_gallery_init',
5646
'frontend/js/shortcode.min.js',
@@ -70,6 +60,7 @@ public static function register_scripts_styles() {
7060
array( 'jquery' )
7161
);
7262
Script_And_Style_Helpers::register_script( 'sgdg_justified-layout', 'bundled/justified-layout.min.js' );
63+
add_shortcode( 'sgdg', array( self::class, 'render' ) );
7364
}
7465

7566
/**

0 commit comments

Comments
 (0)