Correct way to output styles gathered from theme or plugin settings?

Question

I have built a Timeline plugin and used Carbonfields to add a settings page in which users can select the colours of each element in their timelines.

The plugin has default colours in the main stylesheet and I am currently using wp_add_inline_style() to fetch the saved colours from wp_options and output them (attaching to the main stylesheet.

This works fine but is this normally how you would output styles set in a theme?
If not, what is the best approach, or the ‘correct’ WP way to do it?

EDIT: Here is a cut down example of how I’ve implemented this currently.

// ENQUEUE ADMIN STYLES
function simple_timeline_admin_style() {
    wp_register_style( 'timeline-admin-styles', plugins_url('admin/css/admin-styles.css',__FILE__ ));
    wp_enqueue_style('timeline-admin-styles');

    simple_timelines_colours();
}
add_action('admin_enqueue_scripts', 'simple_timeline_admin_style');

//Add Custom Timeline Colours
function simple_timelines_colours() {

    $title_colour = carbon_get_theme_option('st_timeline_title_colour');

    $custom_css = "";


    if ( $title_colour ) {
        $custom_css .="
        article[id^='simple-timeline-'] .simple-timeline-title h2 {
            color: {$title_colour};
        }";
    }

wp_add_inline_style( 'timeline-admin-styles', $custom_css );

}

0
, mike_temby 3 years 2020-04-01T20:51:10-05:00 0 Answers 86 views 0

Leave an answer

Browse
Browse