WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to create a few extra theme options in the "customise" section of the wp admin menu. I would like to offer an option to load an alternative style sheet.

Question: How can I adapt the following code to replace the stylesheet name "posts.css" with a user-selected option?

function theme_styles()  
 // Register the style like this for a theme:  
 // (First the unique name for the style (custom-style) then the src, 
 // then dependencies and ver no. and media type)
 wp_register_style( 'custom-style', 
get_template_directory_uri() . '/posts.css', 
'all' );

// enqueing:
wp_enqueue_style( 'custom-style' );
add_action('wp_enqueue_scripts', 'theme_styles');

This is the particular line of code I am having trouble with - I have tried this, where 'posts' is a theme option and 'style.css' is a default - but it gives a blank page:

get_template_directory_uri() . '/<?php echo get_theme_mod( 'posts', 'style.css' ); ?>', 

And this is how I added the alternative stylesheet option to the wp menu incase it matters:

$wp_customize->add_setting( 'posts', array(
    'default'        => 'style.css',
) );

$wp_customize->add_control( 'posts', array(
    'label'   => 'Post Blocks',
    'section' => 'themedemo_demo_settings',
'type'       => 'select',
'choices'    => array(
    'style.css' => 'Default',
    'posts.css' => 'No blocks',
) );


share|improve this question
up vote 2 down vote accepted

You're trying to execute PHP in a string - you just need:

get_template_directory_uri() . '/' . get_theme_mod( 'posts', 'style.css' ),
share|improve this answer
Brilliant! Sorry for all the dumb questions, but I am learning as I go - Thanks – speedypancake Nov 4 '12 at 16:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.