{"id":9499,"date":"2022-02-09T13:23:29","date_gmt":"2022-02-09T11:23:29","guid":{"rendered":"https:\/\/maxservices.gr\/wordpress-function-add-css-based-on-url\/"},"modified":"2022-02-09T13:23:29","modified_gmt":"2022-02-09T11:23:29","slug":"wordpress-function-add-css-based-on-url","status":"publish","type":"post","link":"https:\/\/maxservices.gr\/en\/wordpress-function-add-css-based-on-url\/","title":{"rendered":"WordPress function: Add CSS based on url"},"content":{"rendered":"
If you want to add CSS to a compared page or category-taxonomy etc, here’s a quick way:<\/p>\n
\n\n\/\/ Function to apply css on specific page url by NicolasLagios.com\nadd_action( 'init', 'css_me_bash_to_url_by_Nicolas' );\nfunction css_me_bash_to_url_by_Nicolas() {\n\n$url = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];\n\nif ( false !== strpos( $url, 'string' ) ) { \/\/here we change the string as we want, eg for mysite.com\/site\/something\/somethingelse.html , we put the word "something"\necho '<code class="php plain"><style type=<\/code><code class="php string">"text\/css"<\/code><code class="php plain">><\/code> \/*here we write css code*\/ <\/style>'; } } <\/pre>\n\n
- We change the string<\/li>\n
- We write the css<\/li>\n
- We put the function in the child theme or in the my custom functions plugin<\/li>\n<\/ol>\n
If you need help<\/p>\n
Original Source: https:\/\/nicolaslagios.com\/wordpress-%cf%83%cf%85%ce%bd%ce%ac%cf%81%cf%84%ce%b7%cf%83%ce%b7-%cf%80%cf%81%ce%bf%cf%83%ce%b8%ce%ae%ce%ba%ce%b7-css-%ce%bc%ce%b5-%ce%b2%ce%ac%cf%83%ce%b7-%cf%84%ce%bf-url\/<\/p>\n","protected":false},"excerpt":{"rendered":"
If you want to add CSS to a compared page or category-taxonomy etc, here’s a quick way: We change the string We write the css <\/p>\n","protected":false},"author":1,"featured_media":8374,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[586,581,236,582,580,579,584],"tags":[585,587,583],"acf":[],"yoast_head":"\n
Wordpress function: Add CSS based on url - Max Services<\/title>\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n\t\n\n\n\t\n\t\n\t\n