So I’m creating a simple plugin for wordpress that will load new block patterns. I’ve got everything working except for one thing which is enqueueing stylesheets. I’ve done some research and tried to figure it out but I’m not sure where my code has gone wrong.
/**
* Load CSS
*/
function sebootscout_enqueue_frontend() {
wp_enqueue_style( 'sebootscout-block-patterns', plugins_url( 'sebootscout-block-style.css', __DIR__ ), array(), '1.0' );
}
add_action( 'wp_enqueue_scripts', 'sebootscout_enqueue_frontend' );
2
Answers
I always use something like the following. Also making sure I’m actually getting the correct path to the file. The browser developer tools to help show that.
First you need to register the style
If the file which calls this action is nested and not inside plugin’s root folder then replace
with
Finally wherever you want to load the specific registered style
Make sure the theme you are testing this on has
wp_head();
before</head>
on header.phpand
wp_footer();
before</body>
on footer.phpThis is because wordpress actually uses those 2 functions to hook your style to the DOM depending on the option to load it on footer or not.
Hope this helps and wish you luck.