Show Post Excerpt Prior to Patreon Button?


#1

Hey! Is there a way to show excerpts of content (as a sort of sample) and then the Patreon button? Thanks! DH


#2

By Patreon button, you mean the ‘UNLOCK’ button that sends the user to the Patreon flow?


#3

Correct. Thanks for clarifying. So, basically, is there a way to have an excerpt of a protected post visible to entice users into the Patreon flow?


#4

Currently there isnt a means to do that. The locking mechanism takes entire final output of the content and locks it.

However, you can achieve this by hooking to ptrn/post_content filter. This is applied to final return that comes from the locked post.

If you just get the excerpt and append it in front of the content in a function that you hooked to this filter, it would achieve what you want to do.


#5

Here is an example code that you can put in a plugin or your theme’s functions.php:

add_filter('ptrn/post_content','my_excerpt_adding_function');

function my_excerpt_adding_function($content) {

global $post;

$excerpt = get_the_excerpt($post);

// Format the excerpt in any way you want after this point

return $excerpt.$content;


}

#6

This is great but got this error when I put it in my theme’s functions.php:

syntax error, unexpected 'global' (T_GLOBAL)

Any ideas? DH

codebard

    February 26

Here is an example code that you can put in a plugin or your theme’s functions.php:

> 
> add_filter('ptrn/post_content','my_excerpt_adding_function');
> my_excerpt_adding_function($content) {
> global $post;
> $excerpt = get_the_excerpt($post);
> // Format the excerpt in any way you want after this point
> return $excerpt.$content;
> }

#7

Please make the below correction:

my_excerpt_adding_function

to

function my_excerpt_adding_function


#8

Thanks! No longer getting the error. However, the behavior is not what we expected. With the new function added to the functions.php of the theme, only the most recent post is viewable and everything else, including breadcrumbs, is no longer visible.


#9

And when I try to roll it back, there’s a nonce_failure error now. Advice?


#10

Ok, successfully restored the functions.php. How shall we proceed?


#11

This means that you were talking about post listings, not an individual post. So you wanted to add excerpts to post listings, not the individual post.

Is that right?


#12

I would like excerpts visible in both posts and post listings. Thanks!


#13

Please try this code:

add_filter('ptrn/post_content','my_excerpt_adding_function');

function my_excerpt_adding_function($content) {

	global $post;

	add_filter('ptrn/bypass_filtering','toggle_patreon_filtering');
	
	$excerpt = get_the_excerpt($post);
	
	remove_filter('ptrn/bypass_filtering','toggle_patreon_filtering');
	
	// Format the excerpt in any way you want after this point

	return $excerpt.$content;

}

function toggle_patreon_filtering($filter) {
	
	if(!$filter) {
		return true;		
	}	
	return false;
}

#14

Works great! Thanks for all your effort and expertise. Much appreciated! DH

codebard

    February 26

Please try this code:

> add_filter('ptrn/post_content','my_excerpt_adding_function')
> 
> ;
> function my_excerpt_adding_function($content) {
> global $post;
> add_filter('ptrn/bypass_filtering','toggle_patreon_filtering');
> $excerpt = get_the_excerpt($post);
> remove_filter('ptrn/bypass_filtering','toggle_patreon_filtering');
> // Format the excerpt in any way you want after this point
> return $excerpt.$content;
> }
> function toggle_patreon_filtering($filter) {
> if(!$filter) {
> return true; } return false;
> }