Hook to add a CSS class to a specific HTML element in posts

Hey,

What would the filter/action be in case I wanted to add a CSS class to, for example, the <div class="entry-content content"> HTML element (that is output by the theme template) but just for (single) posts? The result would be something like <div class="entry-content content custom-class">.

Regards,
Diego

Hi Diego,

You can make use of the child theme concept, if you don’t have a child theme activated, check this guide:

After that, that’s the file you need to copy in your child theme directory:

/x/framework/views/global/_content-the-content.php

You will find that specific line you mentioned:

<div class="entry-content content">

Which you can wrap it between is_single conditional tag:

https://developer.wordpress.org/reference/functions/is_single/

Also, check this guide while implementing this conditional tag:

https://developer.wordpress.org/reference/functions/is_single/

As this is all custom development, regretfully we wont be able to assist further. Custom development is outside the scope of our support. We are happy to provide advice and get you started in the right direction, but you would still be responsible for the implementation. And moreover, this solution may not work after several updates especially if the themes structure changed or overridden.

Thanks.

Hi @Alaa,

Your help is very much appreciated.

What you describe is what I I had actually done. I was just wondering if there was a more elegant way to do it using a hook.

Thank you!

Hi there,

There are also some hook available for X and Pro that you may use.

Please check this link for that:

Hope this helps.

Thanks @Jade! I’ll take a look at it.

You’re most welcome!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.