Jump to content

Catching all classes and IDs from a CSS Stylesheet that contain a certain search term


Sofian777

Recommended Posts

I am using a WordPress premium theme that has a 25.000+ lines styles.css. I want to change the font and main color sitewide, and for this I would like to catch ALL classes and IDs that use them for my childtheme.

 

Manually searching through 25.000 lines and then selecting and copying the classes together is a very slow procedure, and I am sure this can be automated with RegEx, but I only know that it exists but not how it works, especially not for such a vast function.

 

But at least I could figure out the logic that a script for such a task would need to follow.

 

So let's say I need a rule that collects ALL classes to which Roboto is assigned.

Basically it needs to

1. find Roboto, then

2. go back to the { and

3. collect everything before { until

4. the last } before, so it needs to go backwards searching

5. Then it needs to add a comma to the last entry, so the list can continue.

The result will be a very big list of comma-separated classes which I can then easily assign the new font to.

 

Can someone figure out such a RegEx String, or better to say, write such a php script?

 

 

 

...
...
last CSS rule ending here.

}

 

.td-page-content blockquote p,

.td-post-content blockquote p,

.wpb_text_column blockquote p,

.td_block_text_with_title blockquote p,

.bbpress blockquote p,

.woocommerce #tab-description blockquote p,

.mce-content-body blockquote p,

.comment-content blockquote p

{

  font-family: 'Roboto', sans-serif;

  font-size: 32px;

  line-height: 40px;

  font-weight: 400;

  font-style: italic;

  text-align: center;

  text-transform: uppercase;

  color: ...

 

...
...
...

Looks like you are wanting to change the font for all p tags within blockquote tags, in that case put the following at the end of your style.

blockquote p 
{
  font-family: 'Roboto', sans-serif;
  font-size: 32px;
  line-height: 40px;
  font-weight: 400;
  font-style: italic;
  text-align: center;
  text-transform: uppercase;
  color: ...
}

Thanks for your answer, but the above code is just an example, I don't want to change only blockquotes. I want to create a list of all classes and ID's to which roboto is assigned. With a script running through a large CSS file, outputting a list of all classes that I can then use in my child-theme to change roboto in all instances where the main theme has set it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.