WordPress – Add CSS to a Single Post

Add the following immediately before the call to wp_head:

/*If the post has the 'css' custom field, load a stylesheet
	 *The stylesheet to load is based on the value of the 'css' field
	 */
	if ( get_post_meta($post->ID, 'css', true) ) {
		$style = get_post_meta($post->ID, 'css', true);
		$stylepath = get_bloginfo('template_url') . '/css/' . $style . '.css';
		echo "<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"$stylepath\" />\n";
	}


For example, if you want to use a stylesheet called custom.css on your post, you’ll have to create a folder in your theme directory called css and put your stylesheet there (for me the path would be www.domainname.com/wp-content/themes/yourtheme/css). Then add a Custom Field to your post named css with the value custom.


Geplaatst

in

, ,

door

Tags:

Reacties

Geef een reactie

Het e-mailadres wordt niet gepubliceerd. Vereiste velden zijn gemarkeerd met *