Skip Navigation

[Resolved] Conditional to check if post/page is using a Toolset content template

This support ticket is created 2 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 4 replies, has 2 voices.

Last updated by Shawn 2 years, 4 months ago.

Assisted by: Waqar.

Author
Posts
#2241043

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?

#2241273

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

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

#2241797

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;
    }
}
#2243197

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

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.

#2243651

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.