WordPress PHP function: Add CSS based on url
- February 9, 2022
- -
- CSS PHP Programming Programming Websites & Hosting Wordpress
- -
- nicolas
If you want to add CSS to a compared page or category-taxonomy etc, here's a quick way:
// Function to apply css on specific page url by NicolasLagios.com add_action( 'init', 'css_me_bash_to_url_by_Nicolas' ); function css_me_bash_to_url_by_Nicolas() { $url = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; if ( false !== strpos( $url, 'string' ) ) { //edw allazoume to string opws epithimoume, px gia to sitemoy.com/site/kati/katiallo.html , tha baloume "kati" echo '<style type="text/css"> /* here we write the sss */ </style>'; } }
- We change the string
- We write the css
- We put the function in the child theme or in the my custom functions plugin
If you need help
This post is also available in: Ελληνικά