Archived topic
Custom attributes on entry-content class div on single post page
1 reply · Started by Nemanja on November 17, 2022
Hi there
Another Outseta memberships content locking question:
In order to show post content only to subscribers and show "subscribe now" element to the non-subscribers, we need to put Outseta's custom attributes:
data-o-anonymous ==> for logged out
data-o-authenticated ==> for logged in and subscribed
For more context, their documentaion says the following:
If you want to show your page element to users on specific subscription plans, separate the Uids for each plan with a coma. The resulting format should be:
data-o-plan-content="planUid1,planUid2"If you want to hide your page element from users on specific subscription plans, prefix the plan Uid with an exclamation point:
data-o-plan-content="!planUid1,!planUid2"
We would need to add a custom attribute on the hook that produces "entry-content" class div on single post.

How would we go about doing that?
Thanks!
Hi there,
you would need to use a Child Theme, so you can create your own content-single.php template.
Copy the original template from here:
https://github.com/tomusborne/generatepress/blob/master/content-single.php
And this line is what you need to change:
<div class="entry-content"<?php echo $itemprop; // phpcs:ignore -- No escaping needed. ?>>
For example you could add your own filter hook to it like so:
<div class="entry-content"<?php echo apply_filters('my_custom_filter', $data ); echo $itemprop; /* phpcs:ignore -- No escaping needed. */?>>
And the in your functions you can use the filter like so:
add_filter('my_custom_filter', function($data) {
if ( is_user_logged_in() && in_array( 'subcriber', (array) $user->roles ) ) {
// do something for logged in subscribers
$data = 'data-o-authenticated';
} else {
// do something for others
$data = 'data-o-anonymous';
}
return $data;
});
You will need to check what template tags you require in your IF conditions for determining the user logged in role.