I'm developing a site using a child theme of GeneratePress. I'd like to remove some parent theme action hooks via functions.php, but only when the post/page is using a Toolset Content Template. In other words, if the post/page doesn't have a Toolset content template assigned, the child theme does nothing. Is this possible?
Hi,
Thank you for contacting us and I'd be happy to assist.
If you have the ID of the target page/post to check for the content template assignment, you can use the "has_wpv_content_template" function:
https://toolset.com/documentation/programmer-reference/views-api/#has_wpv_content_template
I hope this helps and please let me know if you need any further assistance around this.
regards,
Waqar
I ended up with this in my functions.php file... Do you see any issues with doing this? Am I using the correct hook ('wp')?
add_action( 'wp', 'sbgd_remove_parent_actions' );
function sbgd_remove_parent_actions() {
global $post;
// Returns the ID of the assigned Content Template or 0 if there is no one
$has_ct_assigned = has_wpv_content_template( $post->ID );
if ( $has_ct_assigned > 0 ) {
// Has a Content Template assigned.
add_filter( 'generate_show_entry_header', '__return_false' );
remove_action( 'generate_after_header', 'generate_featured_page_header', 10 );
remove_action( 'generate_before_content', 'generate_featured_page_header_inside_single', 10 );
} else {
return;
}
}
Thanks for the update and your function looks good.
The hook "wp" executes when the WordPress environment has been set up, so using it should be safe and shouldn't result in any issue.
My issue is resolved now. Thank you!