WordPress.org

Ready to get started?Download WordPress

Forums

Using theme options to modify CSS (3 posts)

  1. snthr
    Member
    Posted 3 years ago #

    Hi.

    I had a look around and I couldn't find an exact answer to this question...

    I'm making a theme at the moment, and I'm including some theme options. I have the basics working, but I need to know the 'best practice' ways of doing a couple of things.

    Specifically, I want users of my theme to be able to set their own link colour. To do this, I need to re-write the default link colour in my CSS file with whatever they want. As far as I am aware, you can't directly use PHP in a CSS file (not without renaming it to something like styles.css.php, which I don't want to do).

    A lot of themes allow this ability to set link colours -- is there a standard or accepted way that they do this? How do they do it without using PHP in their CSS?

    Thanks.

  2. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    They use css in their php! It can be printed as inline css using wp_head, which allows it to be output in the <head> section of the site

    add_action( 'wp_head', 'voodoo_inline_css', 100000 );
    
    if( get_theme_option( 'custom_css' ) )
    		theme_option( 'custom_css' ); 
    
    	do_action( 'voodoo_inline_css' );

    I have a custom_css option where users can input the css, then it gets added in

  3. snthr
    Member
    Posted 3 years ago #

    Thanks for the info.

    I'm not sure I really understand you, though. The code you posted -- where does that go? Into functions.php or somewhere like that?

    How would I add several CSS options for a user to mess with in the theme?

    Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic