{"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 '&lt;code class="php plain"&gt;&lt;style type=&lt;\/code&gt;&lt;code class="php string"&gt;"text\/css"&lt;\/code&gt;&lt;code class="php plain"&gt;&gt;&lt;\/code&gt; \/*here we write css code*\/ &lt;\/style&gt;'; } }  <\/pre>\n
    \n
  1. We change the string<\/li>\n
  2. We write the css<\/li>\n
  3. 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":"\nWordpress function: Add CSS based on url - Max Services<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/maxservices.gr\/en\/wordpress-function-add-css-based-on-url\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Wordpress function: Add CSS based on url\" \/>\n<meta property=\"og:description\" content=\"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\" \/>\n<meta property=\"og:url\" content=\"https:\/\/maxservices.gr\/en\/wordpress-function-add-css-based-on-url\/\" \/>\n<meta property=\"og:site_name\" content=\"Max Services\" \/>\n<meta property=\"article:published_time\" content=\"2022-02-09T11:23:29+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/maxservices.gr\/wp-content\/uploads\/2022\/04\/unnamed-file.css.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"674\" \/>\n\t<meta property=\"og:image:height\" content=\"398\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nicolas\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":[\"Organization\",\"Place\"],\"@id\":\"https:\/\/maxservices.gr\/#organization\",\"name\":\"Max Services\",\"url\":\"https:\/\/maxservices.gr\/\",\"sameAs\":[],\"logo\":{\"@id\":\"https:\/\/maxservices.gr\/en\/wordpress-function-add-css-based-on-url\/#local-main-organization-logo\"},\"image\":{\"@id\":\"https:\/\/maxservices.gr\/en\/wordpress-function-add-css-based-on-url\/#local-main-organization-logo\"},\"openingHoursSpecification\":[{\"@type\":\"OpeningHoursSpecification\",\"dayOfWeek\":[\"Monday\",\"Tuesday\",\"Wednesday\",\"Thursday\",\"Friday\",\"Saturday\",\"Sunday\"],\"opens\":\"09:00\",\"closes\":\"17:00\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/maxservices.gr\/#website\",\"url\":\"https:\/\/maxservices.gr\/\",\"name\":\"Max Services\",\"description\":\"\u03a5\u03c0\u03b7\u03c1\u03b5\u03c3\u03af\u03b5\u03c2 \u0394\u03b9\u03b1\u03b4\u03b9\u03ba\u03c4\u03cd\u03bf\u03c5 & \u03a6\u03b9\u03bb\u03bf\u03be\u03b5\u03bd\u03af\u03b1\u03c2\",\"publisher\":{\"@id\":\"https:\/\/maxservices.gr\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/maxservices.gr\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/maxservices.gr\/en\/wordpress-function-add-css-based-on-url\/#primaryimage\",\"url\":\"https:\/\/maxservices.gr\/wp-content\/uploads\/2022\/04\/unnamed-file.css.jpg\",\"contentUrl\":\"https:\/\/maxservices.gr\/wp-content\/uploads\/2022\/04\/unnamed-file.css.jpg\",\"width\":674,\"height\":398},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/maxservices.gr\/en\/wordpress-function-add-css-based-on-url\/#webpage\",\"url\":\"https:\/\/maxservices.gr\/en\/wordpress-function-add-css-based-on-url\/\",\"name\":\"Wordpress function: Add CSS based on url - Max Services\",\"isPartOf\":{\"@id\":\"https:\/\/maxservices.gr\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/maxservices.gr\/en\/wordpress-function-add-css-based-on-url\/#primaryimage\"},\"datePublished\":\"2022-02-09T11:23:29+00:00\",\"dateModified\":\"2022-02-09T11:23:29+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/maxservices.gr\/en\/wordpress-function-add-css-based-on-url\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/maxservices.gr\/en\/wordpress-function-add-css-based-on-url\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/maxservices.gr\/en\/wordpress-function-add-css-based-on-url\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/maxservices.gr\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"WordPress function: Add CSS based on url\"}]},{\"@type\":\"Article\",\"@id\":\"https:\/\/maxservices.gr\/en\/wordpress-function-add-css-based-on-url\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/maxservices.gr\/en\/wordpress-function-add-css-based-on-url\/#webpage\"},\"author\":{\"@id\":\"https:\/\/maxservices.gr\/#\/schema\/person\/c1c4c81d69db4604ff60b48002adc5a7\"},\"headline\":\"WordPress function: Add CSS based on url\",\"datePublished\":\"2022-02-09T11:23:29+00:00\",\"dateModified\":\"2022-02-09T11:23:29+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/maxservices.gr\/en\/wordpress-function-add-css-based-on-url\/#webpage\"},\"wordCount\":235,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/maxservices.gr\/#organization\"},\"image\":{\"@id\":\"https:\/\/maxservices.gr\/en\/wordpress-function-add-css-based-on-url\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/maxservices.gr\/wp-content\/uploads\/2022\/04\/unnamed-file.css.jpg\",\"keywords\":[\"Websites & Hosting>Wordpress>Programming\",\"CSS>Programming\",\"PHP>Programming\"],\"articleSection\":{\"0\":\"CSS\",\"1\":\"PHP\",\"3\":\"Wordpress\",\"4\":\"Websites & Hosting\",\"5\":\"Programming\",\"6\":\"Programming\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/maxservices.gr\/en\/wordpress-function-add-css-based-on-url\/#respond\"]}],\"copyrightYear\":\"2022\",\"copyrightHolder\":{\"@id\":\"https:\/\/maxservices.gr\/#organization\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/maxservices.gr\/#\/schema\/person\/c1c4c81d69db4604ff60b48002adc5a7\",\"name\":\"Nicolas\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/maxservices.gr\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/8b2c794829f3cd47775142b85a598a02?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/8b2c794829f3cd47775142b85a598a02?s=96&d=mm&r=g\",\"caption\":\"Nicolas\"},\"sameAs\":[\"http:\/\/maxservices.gr\"],\"url\":\"https:\/\/maxservices.gr\/en\/author\/webmaster\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/maxservices.gr\/en\/wordpress-function-add-css-based-on-url\/#local-main-organization-logo\",\"url\":\"https:\/\/maxservices.gr\/wp-content\/uploads\/2022\/06\/maxservices_ig_profile.jpg\",\"contentUrl\":\"https:\/\/maxservices.gr\/wp-content\/uploads\/2022\/06\/maxservices_ig_profile.jpg\",\"width\":360,\"height\":360,\"caption\":\"Max Services\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Wordpress function: Add CSS based on url - Max Services","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/maxservices.gr\/en\/wordpress-function-add-css-based-on-url\/","og_locale":"en_US","og_type":"article","og_title":"Wordpress function: Add CSS based on url","og_description":"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","og_url":"https:\/\/maxservices.gr\/en\/wordpress-function-add-css-based-on-url\/","og_site_name":"Max Services","article_published_time":"2022-02-09T11:23:29+00:00","og_image":[{"width":674,"height":398,"url":"https:\/\/maxservices.gr\/wp-content\/uploads\/2022\/04\/unnamed-file.css.jpg","type":"image\/jpeg"}],"twitter_card":"summary_large_image","twitter_misc":{"Written by":"Nicolas","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Organization","Place"],"@id":"https:\/\/maxservices.gr\/#organization","name":"Max Services","url":"https:\/\/maxservices.gr\/","sameAs":[],"logo":{"@id":"https:\/\/maxservices.gr\/en\/wordpress-function-add-css-based-on-url\/#local-main-organization-logo"},"image":{"@id":"https:\/\/maxservices.gr\/en\/wordpress-function-add-css-based-on-url\/#local-main-organization-logo"},"openingHoursSpecification":[{"@type":"OpeningHoursSpecification","dayOfWeek":["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],"opens":"09:00","closes":"17:00"}]},{"@type":"WebSite","@id":"https:\/\/maxservices.gr\/#website","url":"https:\/\/maxservices.gr\/","name":"Max Services","description":"\u03a5\u03c0\u03b7\u03c1\u03b5\u03c3\u03af\u03b5\u03c2 \u0394\u03b9\u03b1\u03b4\u03b9\u03ba\u03c4\u03cd\u03bf\u03c5 & \u03a6\u03b9\u03bb\u03bf\u03be\u03b5\u03bd\u03af\u03b1\u03c2","publisher":{"@id":"https:\/\/maxservices.gr\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/maxservices.gr\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/maxservices.gr\/en\/wordpress-function-add-css-based-on-url\/#primaryimage","url":"https:\/\/maxservices.gr\/wp-content\/uploads\/2022\/04\/unnamed-file.css.jpg","contentUrl":"https:\/\/maxservices.gr\/wp-content\/uploads\/2022\/04\/unnamed-file.css.jpg","width":674,"height":398},{"@type":"WebPage","@id":"https:\/\/maxservices.gr\/en\/wordpress-function-add-css-based-on-url\/#webpage","url":"https:\/\/maxservices.gr\/en\/wordpress-function-add-css-based-on-url\/","name":"Wordpress function: Add CSS based on url - Max Services","isPartOf":{"@id":"https:\/\/maxservices.gr\/#website"},"primaryImageOfPage":{"@id":"https:\/\/maxservices.gr\/en\/wordpress-function-add-css-based-on-url\/#primaryimage"},"datePublished":"2022-02-09T11:23:29+00:00","dateModified":"2022-02-09T11:23:29+00:00","breadcrumb":{"@id":"https:\/\/maxservices.gr\/en\/wordpress-function-add-css-based-on-url\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/maxservices.gr\/en\/wordpress-function-add-css-based-on-url\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/maxservices.gr\/en\/wordpress-function-add-css-based-on-url\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/maxservices.gr\/en\/"},{"@type":"ListItem","position":2,"name":"WordPress function: Add CSS based on url"}]},{"@type":"Article","@id":"https:\/\/maxservices.gr\/en\/wordpress-function-add-css-based-on-url\/#article","isPartOf":{"@id":"https:\/\/maxservices.gr\/en\/wordpress-function-add-css-based-on-url\/#webpage"},"author":{"@id":"https:\/\/maxservices.gr\/#\/schema\/person\/c1c4c81d69db4604ff60b48002adc5a7"},"headline":"WordPress function: Add CSS based on url","datePublished":"2022-02-09T11:23:29+00:00","dateModified":"2022-02-09T11:23:29+00:00","mainEntityOfPage":{"@id":"https:\/\/maxservices.gr\/en\/wordpress-function-add-css-based-on-url\/#webpage"},"wordCount":235,"commentCount":0,"publisher":{"@id":"https:\/\/maxservices.gr\/#organization"},"image":{"@id":"https:\/\/maxservices.gr\/en\/wordpress-function-add-css-based-on-url\/#primaryimage"},"thumbnailUrl":"https:\/\/maxservices.gr\/wp-content\/uploads\/2022\/04\/unnamed-file.css.jpg","keywords":["Websites & Hosting>Wordpress>Programming","CSS>Programming","PHP>Programming"],"articleSection":{"0":"CSS","1":"PHP","3":"Wordpress","4":"Websites & Hosting","5":"Programming","6":"Programming"},"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/maxservices.gr\/en\/wordpress-function-add-css-based-on-url\/#respond"]}],"copyrightYear":"2022","copyrightHolder":{"@id":"https:\/\/maxservices.gr\/#organization"}},{"@type":"Person","@id":"https:\/\/maxservices.gr\/#\/schema\/person\/c1c4c81d69db4604ff60b48002adc5a7","name":"Nicolas","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/maxservices.gr\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/8b2c794829f3cd47775142b85a598a02?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8b2c794829f3cd47775142b85a598a02?s=96&d=mm&r=g","caption":"Nicolas"},"sameAs":["http:\/\/maxservices.gr"],"url":"https:\/\/maxservices.gr\/en\/author\/webmaster\/"},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/maxservices.gr\/en\/wordpress-function-add-css-based-on-url\/#local-main-organization-logo","url":"https:\/\/maxservices.gr\/wp-content\/uploads\/2022\/06\/maxservices_ig_profile.jpg","contentUrl":"https:\/\/maxservices.gr\/wp-content\/uploads\/2022\/06\/maxservices_ig_profile.jpg","width":360,"height":360,"caption":"Max Services"}]}},"_links":{"self":[{"href":"https:\/\/maxservices.gr\/en\/wp-json\/wp\/v2\/posts\/9499"}],"collection":[{"href":"https:\/\/maxservices.gr\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/maxservices.gr\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/maxservices.gr\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/maxservices.gr\/en\/wp-json\/wp\/v2\/comments?post=9499"}],"version-history":[{"count":0,"href":"https:\/\/maxservices.gr\/en\/wp-json\/wp\/v2\/posts\/9499\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/maxservices.gr\/en\/wp-json\/wp\/v2\/media\/8374"}],"wp:attachment":[{"href":"https:\/\/maxservices.gr\/en\/wp-json\/wp\/v2\/media?parent=9499"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/maxservices.gr\/en\/wp-json\/wp\/v2\/categories?post=9499"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/maxservices.gr\/en\/wp-json\/wp\/v2\/tags?post=9499"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}