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',
array(),
'20120208',
'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',
),
) );
Thanks
You’re trying to execute PHP in a string – you just need: