WordPress Plugins Course #9. Add our own CSS – .com

Welcome to the ninth installment of the WordPress plugins course. A course that aims to learn how to programming plugins for WordPress.

Today we will see how to create and add our own style sheet to WordPress, either to modify what our plugin displays, or any other element.

This is especially important if our plugin shows something on the frontend, that is, on the web that the user sees. If this is the case, we will surely want to give it a format and style. Let’s see how.

Register and “enqueue” a style sheet in WordPress

The first thing we will do is create a style sheet, that is, we will create our style.css with the CSS code we want. But of course, this is simply not worth it. Next we will need to register it with wp_register_style, and finally “enqueue” it with wp_enqueue_style. Let’s see how:

This is the best way to do it. It is true that there are some faster ways, but at the same time more botched, such as placing the styles inline in the head, making a manual link or even skipping the wp_register_style, but they are poorer ways of doing it, which in some cases will give us an error .

Having said this, you can see that the operation is very simple. You just have to create a CSS file with your code, and then register it (to tell WordPress that it exists)and you put it in queue (to tell WordPress to apply it).

It is important to note that in this case we have applied it to all web pages, but in the event that our CSS is only applicable on certain pages, we should remove it from there through conditionals, so as not to overload the web with CSS useless. We’ll see more of that in the intermediate and advanced course!

See also  Using Custom Post Types in WordPress - .com

Well, now you have material to investigate and do tests, so go ahead, imagination to power. See you in the next class, the last of the basic course. Until then!

Remember that if you will have access to everybody the courses and you can also enjoy everything from .

All chapters in this course:

Loading Facebook Comments ...
Loading Disqus Comments ...