This CSS Stuffing Works, But Is This A Good Practice?

I am trying to include a dynamic css in my plugin, I have been searching anywhere but doesn’t find any case that is similar to what I do. And what I use to do it is by adding a css file directly into the end of my plugin php file after the closing php tag ?> without adding any other stuffs like calling wp head etc.

Here is the example of the code I put directly into the end of my plugin’s file:

<style type="text/css">

   .innertrow { background-color: <?php get_options('css_value');?>}

</style>

Is that a good practice?

4 s
4

You can use wp_add_inline_style() to add to a stylesheet that you’ve already defined, such as in your plugin. This way an options screen or other user settings can affect the final style output.

That could become very tedious, however, depending on how many changes you are giving the user the power over. However, it is the “best practice” as far as I know.

Leave a Comment