The Patreon button is showing up on my learndash course pages

How to do I get the button to not show up on my course pages? I’m guessing the child theme has the courses defined as posts.

Which particular Patreon button is it? What is the exact text?

Like it? Take a second to support Sacil on Patreon and access more content!

It shows up when I click yes on “show button under posts.” I’d like to have them under my real posts, but not under my Learndash course pages.

Ah i see. The button from the button and widgets plugin.

Currently there isnt a way to selectively assign post types to that button. But it is in the to do list for that plugin. It may happen in 1-3 months - until then, you may use the below code by putting it in a custom plugin. You will need to replace in the post type of your learndash course posts. You should test this code in a staging/dev installation first, of course.

add_filter( 'cb_p6_filter_vars_before_content_filters', 'hide_post_button_for_post_type', 10, 1 );


function hide_post_button_for_post_type( $content ) {

	global $post;
	
	$hide_for_post_types = array(
		'enter_your_post_type_here', // Replace with post type for which you want to hide the button
		'enter_more_post_types_like_this', // Add more post types if needed
	);
	
	$hide = false;
	
	if ( isset( $post ) ) {
	
		$post_type = get_post_type( $post->ID )
	
		foreach ( $hide_for_post_types as $key => $value ) {
		
			if (  $post_type == $hide_for_post_types[$key] ) {
				$hide = true;			}
		
		}
	
	}
	
	global $cb_p6;
	
	if ( $hide ) {	
		$cb_p6->opt['post_button']['show_button_under_posts'] = 'no';	
	}
	
	return $content;
	
}

Thank you. I’ve never made a plugin. Do I just make a folder under plugins and then copy and paste this code into a php file and replace the parts that say ‘enter_your_post_type_here’ with the post types?
Thank you

I am working on a staging site.

Try uploading and activating this makeshift plugin.

Code should work. But its not tested. If it creates an issue, just let me know.

Thank you. I just put this in the plugin folder?

You are supposed to edit the file to put the custom post type slug for learndash posts somewhere in there. But that may be a bit advanced in this context.

Courses, Lessons, Quizes, Topics - which one is the post type you want to hide the button for?

I know how to edit it. I just don’t know where to put it.

‘Mfn_Post_Type_Courses’, // Replace with post type for which you want to hide the button
‘Mfn_Post_Type_Lessons’, // Add more post types if needed
‘Mfn_Post_Type_Quiz’, // Add more post types if needed
‘Mfn_Post_Type_Topic’, // Add more post types if needed

I updated the file. I just don’t know where in my cpanel to put it. In the plugin folder?

For this small plugin, you should visit your WP admin, go to Plugins -> Add, and upload this plugin. Then, activate it.

Thank you. I uploaded it and got this message. Parse error : syntax error, unexpected ‘foreach’ (T_FOREACH) on line 39

It seems line 35 in index.php needs a “;”, as in…

$post_type = get_post_type( $post->ID );

You can just replace that line with the above and retry. If it still creates errors, you can email me the file index.php via ozgur@c.patreon.com

Thanks! I wanted to let you know about a plugin I found, too, Freesoul Deactivate Plugins. It lets you turn off individual plugins on specific pages or page types to speed up your site.

Did the custom plugin help you hide buttons on learndash course pages?