Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Seb Soithongsuk
Seb Soithongsuk
2,190 Points

Help editing a CSS file in a WordPress theme

I'm fine editing the CSS of a WordPress theme, but I don't understand why or how my WordPress page is loading a version of the css file I'm editing.

For example, when I look at the source code for my webpage, I see it's referencing the stylesheet ".../media.css?ver=4.2.2" so any changes I make to that media.css file aren't being pulled through. Where does the "?ver=4.2.2" come from and how can I get my changes to come through?

3 Answers

Clinton Hopgood
Clinton Hopgood
7,825 Points

I would recommend adding an additional stylesheet to the theme for the css you write.

Add this line to the bottom of the styles.css file of the theme you're using:

@import url("example.css"); (change example to the name of the file you create)

(styles.css can be found in the themes folder \yourwebsite\wp-content\themes\yourtheme)

This will ensure that it's applied last and will overwrite any css included with the theme.

You can also keep a backup of the css you added, which would otherwise be lost when updating the theme.

Seb Soithongsuk
Seb Soithongsuk
2,190 Points

Thanks for the reply Clinton.

Unfortunately this just provides me with the same issue. The style.css that is linked to on my site is "style.css?ver=4.2.2"

I have noticed just now that the theme I'm using might be version 4.2.2 as well. I'm using The7 theme if that helps.

I'm having the same problem. How can there be different versions of a css stylesheet?

Seb Soithongsuk
Seb Soithongsuk
2,190 Points

After a brief bit of Googling, I initially thought the issue was with server caching, so I raised a ticket with my hosting provider and they found out it's more likely a WordPress versioning issue (feel a bit silly now for relating the version number to the WordPress version number).

So anyway, while I haven't had the chance to explore the fix, I was provided with this link has a solution - http://wordpress.stackexchange.com/questions/132282/removing-wordpress-version-number-from-included-files

David Richied
David Richied
18,057 Points

Hello Seb, I am experiencing this exact same problem with the version being appended to my style.css file. I believe WordPress is making a completely different CSS file and updating is now and then. Did the solution on stackexchange work for you?