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: ...

 

...
...
...

Link to comment
Share on other sites

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: ...
}
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.