Skip Navigation

[Resolved] Add hook to content template

This support ticket is created 2 years, 9 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 4 replies, has 2 voices.

Last updated by Minesh 2 years, 8 months ago.

Assisted by: Minesh.

Author
Posts
#2307303
Screenshot 2022-03-03 at 4.29.30 PM.png

Dear Sir/Madam,

I install the GeneratePress theme, I want to have custom javascript and style for specific post content template, I know how to assign the Hook elements to page but no idea how to assign to specific content template, content template is not a kind of post, it just a layout. Could you suggest me how I can make a hook to specific content template?

Best regards,

Kelvin

#2307413

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

With the latest update, Toolset Blocks 1.5, the content template used by a post is no longer stored in postmeta table because of the conditional template assignment. Now we need to use the following filter to retrieve the ID of the template that will be used for a post using its $post object:

global $post;
$template_id = apply_filters( 'wpv_content_template_for_post', 0, $post );

You can use the above filter to get the template ID and based on that you can hook your custom CSS/JS.

Please check following errata as well as this is known issue when you use generate blocks:
- https://toolset.com/errata/generateblocks-styles-lost-on-front-end-when-using-content-templates/

#2309155

Dear Minesh,

Sorry I have no idea how I can hook the meta header if I know the $template_id, could you please explain more details ?

#2310061

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please share problem URL where you want to add the custom javascript and CSS and for what content template.

I will try to build to solution based on your actual requirement and then will share the solution.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2322747

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I understand what you are looking for but there is no GUI offered for such things.

I tried to loggedin using the access details you shared but I do not able to access full site, even I do not able to access Toolset menu. If you can tell me to what content template and based on what condition you want to add some CSS or JS?

Toolset offers GUI way to display content template based on the conditoins:
=> https://toolset.com/course-lesson/assigning-templates-to-posts-conditionally/#steps-for-assigning-a-template-conditionally

You may would like to check if that helps you, then you can set the condition accordingly and add a HTML element that will hold the CSS link you want to add.