I see wp_register_style and wp_enqueue_style everywhere whenver I check other Wordpress plugin files.
public function cmc_shortcode_style() {
wp_register_style( 'cmc-shortcodes-style', plugins_url( 'assets/css/cmc-shortcodes.css', __FILE__ ), array(), '1.0.0', 'all' );
wp_enqueue_style( 'cmc-shortcodes-style' );
}
add_action( 'wp_enqueue_scripts', array( $this, 'cmc_shortcode_style' ) );
I also read the Wordpress document and found out that it works similar as include or require.
Then why don't they just use include?
include (ABSPATH . '/wp-content/plugins/cmc/assets/css/cmc-shortcodes.css');
Hmm...There would be a definite reason 'cause everyone is using it.
Those functions are used for several reasons:
jquery
as a dependency and WordPress will make sure your JS is loaded later. Similarly, if you need Masonry, you can use jquery-masonry
and both jQuery and Masonry will be loaded in the correct orderThat's just off the top of my head, probably a bunch more