This might come close to what you want.
Add the below code inside your theme functions.php. Then create a new css file, the filename is base on your user “login” name (i.e, login-name.css, jake.css, admin.css) then upload it within your template root directory (same location with the functions.php).
/**
* Auto include author stylesheet on WP single and custom page view.
* @author Avice D (ChaosKaizer)
* @see WP_Styles
*/
function wp_auto_include_author_css()
{ global $wp_query;
$css_path = TEMPLATEPATH.DIRECTORY_SEPARATOR;
$css_url = get_bloginfo('template_url').'/';
if ($wp_query->is_single || $wp_qeury->is_page){
$po = $wp_query->get_queried_object();
$author_name = sanitize_title_with_dashes(strtolower(get_author_name($po->post_author)));
unset($po);
$filename = $author_name.'.css';
$handle = $author_name.'-stylesheet';
if (file_exists($css_path.$filename)){
wp_register_style($handle, $css_url.$filename);
wp_enqueue_style($handle);
wp_print_styles();
}
}
}
add_action('wp_head','wp_auto_include_author_css');
If your log-in name is “John Doe” it will look for john-doe.css. Space is replace with dash and all characters is in lowercase.
Very close, indeed. It seems to work properly for blog posts but not for pages. Any ideas? Much thanks!
true, my mistake ;(
find
if ($wp_query->is_single || $wp_qeury->is_page){
replace with
if ($wp_query->is_single || $wp_query->is_page){
..
/**
* Auto include author stylesheet on WP single and custom page view.
* @author Avice D (ChaosKaizer)
* @see WP_Styles
*/
function wp_auto_include_author_css()
{ global $wp_query;
$css_path = TEMPLATEPATH.DIRECTORY_SEPARATOR;
$css_url = trailingslashit(get_bloginfo('template_url'));
if ($wp_query->is_single || $wp_query->is_page){
$po = $wp_query->get_queried_object();
$author_name = sanitize_title_with_dashes(strtolower(get_author_name($po->post_author)));
unset($po);
$filename = $author_name.'.css';
$handle = $author_name.'-stylesheet';
if (file_exists($css_path.$filename)){
wp_register_style($handle, $css_url.$filename);
wp_enqueue_style($handle);
wp_print_styles();
}
}
}
add_action('wp_head','wp_auto_include_author_css');
Ha Ha… I didn’t even catch that myself. Thank you so much for your code and time… does EXACTLY what I wanted. You F’n ROCK!