my wordpress theme will be styling posts on the index page based on their post-ID class -this will result in a lot of css code over longer durations of time. To keep the website lightweight as possible I wanted to -

a> split this code up into smaller stylesheets, but would also need to -

b> target stylesheets only when relevant to avoid references all the seperate style docs at once, would consider one style for a months worth of posts (set number of posts a day) - I can consider making one stylesheet for each days posts.

c> the index page style needs to be cleared for the permalink style, as the permalink pages will be styled completely differently.

I am not much of a coder however and I'm not sure where to begin, from what I understand somewhere along this following code -

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

I should be injecting some sort of php to pick up the post-ID class and match it to one of the stylesheets.

This would in turn require a filing of the stylesheets in a format where post-ID-class and stylesheet name are relatable.

This would presumably done by running fucntion to check post-ID-number range and match it to stylesheet which is paired with number range which encompasses the post-ID-number.

Would my theorizing above be along the right lines or would you suggest a different method? either way I'm not sure where to begin when it comes to coding this out.

The other method I had in mind was to use custom field (text-field) to hold names of classes that a function would pick up and add to the post's classes. I'm using Advanced Custom Fields as I cant seem to get default custom fields to appear even when disabling ACF, another issue I need help resolving. Even with ACF however, I dont know how to actually take advantage of the custom fields, I've set up the fields and field groups but I'm not sure where to do next.

Any help woould be much appreciated.

  • The above functionality is too complex to be implemented as you will need to have each css called based on the called classes moreover Can you please let me know the reason you need to make different CSS . instead of adding all code in one css Dec 27, 2018 at 7:12

1 Answer 1


Managed to get the custom field method to work, which saves alot of headache in the long run, solution was simple -

<?php post_class(get_field('the-field')); ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.