Site logo

Archived topic

Install the post_class() function

11 replies · Started by Alvern Bullard on April 29, 2021

Viewing posts 1–12 of 12

Hey there,

I working with ConvertFlow and it has a function that recognises categories and tags for pop up personalisation.

It works perfectly when I specify a post by name.

However, when I select a category as one of the conditions to show the pop-up it doesn't seem to work. I visited their knowledgebase and they have suggested the following:

"This might mean your WordPress theme is lacking the post class function, which is how ConvertFlow recognizes categories, tags etc.

Most official WordPress themes have post_class() installed on the body tag of posts and pages.

If you're using a third-party theme, there's a chance this wasn't included, which means ConvertFlow doesn't have a way to tell which category a post belongs to and which tags it has.

To configure this, install the post_class() function on the body tag of your theme's post template - https://developer.wordpress.org/reference/functions/post_class/"

Would you be able to confirm that the post_class() function is already installed on the GeneratePress theme and if it is not, can you give me step by step instructions on how to get it installed?

The link provided by ConvertFlow seem to be missing the install instructions or only caters for people who are developers.

Many thanks,

Alvern

Hi there,

WordPress has the body_class() function for adding the relevant classes to the <body> tag - this is how all of the Official WordPress themes apply classes to the body.

Heres an example of the latest WP (TwentyTwentyOne) theme using that function:

https://github.com/WordPress/twentytwentyone/blob/ba9f20cad89163761185c0467b346ba42541ae22/header.php#L23

And yes, GeneratePress also uses this.

I don't know why they would want the post_class() on the body tag - the Theme does use it for the various content templates.
They can see them in place here:

https://github.com/tomusborne/generatepress/search?q=post_class%28%29

You can share the link to this support topic for the ConvertFlow developers to review.

Hey David,

Thanks for the quick response.

First of all, the application I am using is ConvertFlow NOT ConvertKit.

If I am correct, is it just a matter of adding the code to the body tag (just like a standard tracking code or script) or do I need to edit the GeneratePress theme template?

Is there a brief video or step by step guide on how to get it done if I need to add it to the theme editor?

Thanks,

Alvern

Oops corrected the topic above for ConvertFlow.

It would require editing the Themes header.php - but there should be no need for that. As the body_class() function does exactly the same thing - it outputs all the necessary classes to the body tag.

Can you share a link to an archive so i can take a look if something is not working correctly.

I would also share this topic with ConvertFlow as what they're saying about Officical themes using post_class() in the body is not correct. And if there plugin works correctly with an Official theme we may just need to pass some other classes to the body_class filter.

Hey David,

I have copied your suggestion and sent it over to the folks at ConvertFlow. They normally take a few hours to respond.

In the meantime, I'm not sure that there's a lot I can share with you in terms of links. The way ConvertFlow works is that you can stipulate which categories in WordPress to allow certain pop-ups to show.

You can also specify these pop-ups to show on individual pages or posts.

For example, on these two links, you'll see the pop-ups that I am referring two (both are exit intent pops); https://www.successunscrambled.com/content-repurposing/
https://www.successunscrambled.com/preview-vs-planoly/

Here is a sneak peek of the conditions inside ConvertFlow
ConvertFlow screenshots of their if-then WordPress category conditions

I hope it makes sense.

Thanks,

Alvern

Just to jump in here - post_class() should definitely not be added to the <body> element. This is against WordPress coding standards. We can see here that the official WordPress theme only uses body_class(): https://github.com/WordPress/twentytwentyone/blob/trunk/header.php#L23

Perhaps it's a mistake in their documentation - they should be able to clarify.

Okay Tom,

I'll also send this piece of communication to them.

Thanks,

Alvern

Just some other thoughts.

Are we talking about a Post Category archive OR a post that is in a particular category?
In the second image you provided i see "If visiting WordPress Category" - i would assume this is for the Category Archive.
But i would also there would be "If WordPress post is in Category" or something like that for the single posts.

Yes, David,

If 'WordPress post is in a category' then show the pop-up.

Hopefully, that makes sense.

N.B. The folks at ConvertFlow just responded to say this...

    "Could you link me to the CTA you're targeting based on WordPress categories and the URL where I can test the conditions live? Thanks!
    I'll need to send this over to the dev team so they can go over the documentation and the suggestions sent over by GeneratePress."

Shall we wait to see what ConvertFlow have to say ?

Yes David,

I'm waiting with what I believe is excitement. Lol!!

Haha :) - we wait with bated breath!

This archived topic is closed to new replies.