This is an interesting topic. A WordPress/WooCommerce client could not add CSS via the usual way. In fact, Gravity Forms plugin (and in particular the “directory” extension), stores entries in the database BUT the directory page and the entries filtered list have the same classes, ids, and cannot be “targeted” with CSS.
Long story short, and Gravity Form or not Gravity Form, here’s the snippet you can use to add CSS to any WordPress page as long as you know its URL.
PHP Snippet: Apply CSS to a Page URL That Contains “string”
Please let me know in the comments if everything went as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting.
If you think this code saved you time & money, feel free to join 17,000+ WooCommerce Weekly subscribers for blog post updates and 250+ Business Bloomer supporters for 365 days of WooCommerce benefits. Thank you in advance!
Need Help with WooCommerce?
Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!
Rodolfo Melogli
Business Bloomer Founder
Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.
A very interesting thing happened when I applied the code. I used it for the WooCommerce My Account sub-page “orders” just to change an Elementor element I put above the my account shortcode. It broke the WooCommerce orders table, but only on mobile Safari and mobile Chrome and only the “display: block” attribute did not work anymore. When I changed the font of the table the CSS showed, but the “display” attribute is somehow broken. When I looked at it in Chromes inspect window with mobile view the table was normal. Very odd behaviour. On other pages with tables everything works fine when I use this code. Do you maybe know why the “display” attribute won’t work on the WooCommerce order table because of this code?
Sure. I applied CSS to a row above the orders content from Elementor (which I made to as a navigation through the My Account part), to change the background-color and color of the “buttons” when the specific URL is activated. (you can see it here what happens, if the php code is applied: https://www.magentacloud.de/lnk/TwCFjgXz#file)
Hi! I used this snippet for changing CSS on specific pages where i need. It works perfect BUT:
Can I ask if using it multiple times in a short period gets the Imunify360 to block the ip?
Because that does happen, it changes the CSS of said page and nothing brakes, so before I freak out again I just want to make sure it’s just a safety measure and that I shouldnt worry? Or should I proceed in another way?
Hi, just wanted to let you know that I used something similar ages ago and wanted to use that code again and I was having a blank/couldn’t remenber the exact coding I did, cause I went withouth coding for years, bla bla bla.
TL;DR.
Ur example here is exactly what I used to do and I want to let other users know that it works like a charm.
Questions? Feedback? Support? Leave your Comment Now! _____
If you are writing code, please wrap it between shortcodes: [php]code_here[/php]. Failure to complying with this (as well as going off topic, not writing in English, etc.) will result in comment deletion. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining BloomerArmada to get blog comment reply priority, ask me 1-to-1 WooCommerce questions and enjoy many more perks. Thank you :)
With 100,000 (and growing) monthly organic sessions, Business Bloomer is the most consistent, most active and most complete WooCommerce development/customization blog.
Of course this website itself uses the WooCommerce plugin, the Storefront theme and runs on a WooCommerce-friendly hosting.
NIIIIIIce thanks man!
You’re welcome!
Boom!!!! You are the man!
Thank you so much. I had a Javascript instead if this amazing function.
I just added this to load it in the head.
Thanks
Cool!
A very interesting thing happened when I applied the code. I used it for the WooCommerce My Account sub-page “orders” just to change an Elementor element I put above the my account shortcode. It broke the WooCommerce orders table, but only on mobile Safari and mobile Chrome and only the “display: block” attribute did not work anymore. When I changed the font of the table the CSS showed, but the “display” attribute is somehow broken. When I looked at it in Chromes inspect window with mobile view the table was normal. Very odd behaviour. On other pages with tables everything works fine when I use this code. Do you maybe know why the “display” attribute won’t work on the WooCommerce order table because of this code?
It depends on many things, and first of all on the CSS you applied. Want to share it here maybe?
Sure. I applied CSS to a row above the orders content from Elementor (which I made to as a navigation through the My Account part), to change the background-color and color of the “buttons” when the specific URL is activated. (you can see it here what happens, if the php code is applied: https://www.magentacloud.de/lnk/TwCFjgXz#file)
I applied this code:
This did not work for me – it put the resulting style at the very top of the html output – before the
Where did you place your CSS?
Hi! I used this snippet for changing CSS on specific pages where i need. It works perfect BUT:
Can I ask if using it multiple times in a short period gets the Imunify360 to block the ip?
Because that does happen, it changes the CSS of said page and nothing brakes, so before I freak out again I just want to make sure it’s just a safety measure and that I shouldnt worry? Or should I proceed in another way?
Hi Vanessa, no it shouldn’t
Hi, just wanted to let you know that I used something similar ages ago and wanted to use that code again and I was having a blank/couldn’t remenber the exact coding I did, cause I went withouth coding for years, bla bla bla.
TL;DR.
Ur example here is exactly what I used to do and I want to let other users know that it works like a charm.
Fantastic ๐
Excellent PHP snippet, i changed “strpos” by “strripos” to apply it to last segment of an url
and it’s working!
Thank you
Nice ๐
Thank you so much. This is such a big help. You are awesome!!!
Excellent ๐
Thank you its work’s great !!
๐
hello sir,
What if i want to call class or id of particular division on that page?
Chandan, thanks for your comment! I have no idea I’m afraid, I will need a URL and more information ๐ Thanks!
thank you, this solved a huge problem for me
Awesome, thanks Todd!