require_once( get_template_directory_uri() . '\/includes\/class-php-css.php' );\r\n<\/pre>\nNow here comes the fun part. Once you\u2019ve imported the class and set it up you can begin adding css via filters. Let’s start by creating two actions.<\/p>\n
The first action will add the css to the header, and instantiate our PHP_CSS class to be used within our second hook. We\u2019ll also add the css to the head of the document if our css is not empty.<\/p>\n
add_action( 'wp_head', 'add_theme_header_styles' );\r\nfunction add_theme_header_styles()\r\n{\t\r\n\t\/\/ Instantiate the PHP_CSS object\r\n\t$css = new CarlosRios\\PHP_CSS;\r\n\r\n\t\/**\r\n\t * theme_header_css hook\r\n\t *\r\n\t * Allows you to add css from different areas without having to\r\n\t * instantiate a new instance of the PHP CSS Class every time\r\n\t *\r\n\t * @since 1.0\r\n\t * @param $css Instance of CarlosRios\\PHP_CSS\r\n\t *\/\r\n\tdo_action( 'theme_header_css', $css );\r\n\r\n\t\/\/ Store the output as a string\r\n\t$output = $css->css_output();\r\n\r\n\t\/\/ Check if the output has data, and output it if it does\r\n\tif( !empty( $output ) && $output !== '' ) {\r\n\t\techo '<style>' . $output . '<\/style>';\r\n\t}\r\n}<\/pre>\nThe second action will be where we actually add our css. This hook would be available for any plugin or theme requirement which would want to add css to our header. It comes with one argument, with is the instance of the PHP_CSS class stored in the $css variable.<\/p>\n
add_action( 'theme_header_css', 'add_body_styles' );\r\nfunction add_body_styles( $css )\r\n{\r\n\t\/\/ Set the css for the body\r\n\t$css->set_selector( 'body' );\r\n\t$css->add_properties( array(\r\n\t\t'background'\t=> '#222',\r\n\t\t'color'\t\t=> '#FFF',\r\n\t) );\r\n\r\n\treturn $css;\r\n}\r\n<\/pre>\nNow that we\u2019ve got that setup our theme should contain the css that we added in the theme_header_css hook.<\/p>\n
Create An Advanced CSS Process<\/h3>\n While the method described in this tutorial will certainly get the job done, it’s not actually the best way to do so. Stay tuned for the next part in the series where I\u2019ll show you how to create all of our css via a hook, add that css to a dedicated css file, and then enqueue that file automatically.<\/p>\n","protected":false},"excerpt":{"rendered":"
In the previous part of this series\u00a0I went over the basics of the PHP_CSS class that I created. I showed how it is a much more uniform and easy way to create your custom css with PHP than any other way. In this part, I\u2019ll be showing you how to use css to power your […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"footnotes":""},"categories":[12,8],"tags":[],"yoast_head":"\n
Use CSS To Power Your WordPress Theme<\/title>\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\t \n\t \n\t \n