Skip to content

Commit ac5129c

Browse files
committed
wordpress-snippets
- Added snippet for registering style in a plugin
1 parent 8c71607 commit ac5129c

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
add_action('init', 'my_enqueue_plugin_assets');
4+
function my_enqueue_plugin_assets()
5+
{
6+
wp_register_style('mystyle', get_theme_file_uri('/assets/css/mystyle.css'));
7+
wp_enqueue_style('mystyle');
8+
}

Assets/register-style.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
<?php
1+
<?php
22

33
add_action('init', 'my_enqueue_assets');
4-
function my_enqueue_assets() {
5-
wp_register_style('mystyle', get_theme_file_uri('/assets/css/mystyle.css'));
6-
wp_enqueue_style('mystyle');
7-
}
4+
function my_enqueue_assets()
5+
{
6+
wp_register_style('mystyle', plugins_url('css/style.css', __FILE__));
7+
wp_enqueue_style('mystyle');
8+
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ The list is structured into three sections - links on useful resources and artic
6767
- [Register Image Sizes](https://github.com/bojanfriscic/wordpress-snippets/blob/master/Assets/register-image-sizes.php)
6868
- [Register Script](https://github.com/bojanfriscic/wordpress-snippets/blob/master/Assets/register-script.php)
6969
- [Register Style](https://github.com/bojanfriscic/wordpress-snippets/blob/master/Assets/register-style.php)
70+
- [Register Style in Plugin](https://github.com/bojanfriscic/wordpress-snippets/blob/master/Assets/register-style-in-plugin.php)
7071

7172
### Blocks
7273

0 commit comments

Comments
 (0)