Title: Per Page CSS Selection
Last modified: August 19, 2016

---

# Per Page CSS Selection

 *  [socaljake](https://wordpress.org/support/users/socaljake/)
 * (@socaljake)
 * [17 years, 8 months ago](https://wordpress.org/support/topic/per-page-css-selection/)
 * I think this should be easy to implement but I’ve been searching, probably using
   the wrong set or words in the query.
 * My site uses the HemingwayEx theme, which has multiple CSS files included. All
   of these are fine. What I’d like to do is make it so I can select which CSS file
   to format a page with when I post.
 * When I post it uses abc.css and when my wife posts it uses xyz.css. It doesn’t
   need to be automatic; I’m fine with manually selecting it on the fly.
 * Is this doable? Thanks in advance!
 * -Jake

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [chaoskaizer](https://wordpress.org/support/users/chaoskaizer/)
 * (@chaoskaizer)
 * [17 years, 8 months ago](https://wordpress.org/support/topic/per-page-css-selection/#post-869875)
 * 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.
 *  Thread Starter [socaljake](https://wordpress.org/support/users/socaljake/)
 * (@socaljake)
 * [17 years, 8 months ago](https://wordpress.org/support/topic/per-page-css-selection/#post-869963)
 * **Very close, indeed.** It seems to work properly for blog posts but not for 
   pages. Any ideas? Much thanks!
 *  [chaoskaizer](https://wordpress.org/support/users/chaoskaizer/)
 * (@chaoskaizer)
 * [17 years, 8 months ago](https://wordpress.org/support/topic/per-page-css-selection/#post-869973)
 * 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');
       ```
   
 *  Thread Starter [socaljake](https://wordpress.org/support/users/socaljake/)
 * (@socaljake)
 * [17 years, 8 months ago](https://wordpress.org/support/topic/per-page-css-selection/#post-870036)
 * 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!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Per Page CSS Selection’ is closed to new replies.

## Tags

 * [css](https://wordpress.org/support/topic-tag/css/)
 * [wp_enqueue_style()](https://wordpress.org/support/topic-tag/wp_enqueue_style/)

 * 4 replies
 * 2 participants
 * Last reply from: [socaljake](https://wordpress.org/support/users/socaljake/)
 * Last activity: [17 years, 8 months ago](https://wordpress.org/support/topic/per-page-css-selection/#post-870036)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
