Skip Navigation

[Résolu] Use Content Templates anywhere

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:
How could I display a Content Template's content anywhere on my site (outside of the_content)

Solution:
https://toolset.com/forums/topic/allow-content-templates-to-be-inserted-in-the-pages-head/#post-866899

100% of people find this useful.

This support ticket is created Il y a 6 années et 7 mois. 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Marqué : 

Ce sujet contient 1 réponse, a 2 voix.

Dernière mise à jour par Beda Il y a 6 années et 7 mois.

Assisté par: Beda.

Auteur
Publications
#857830

Content templates currently allow us to take full control over the page body, which is amazing.
It would be even more amazing if we could use the same editor and shortcode to include code in the head of the custom post's page.

Why?
- We can add custom Open Graph Data based on types fields
- Automatic Meta Descriptions based on type fields
- Other tags that we can set

I believe this would give us more freedom to create and to create designs that will be more robust.

Thank you

Adrian

#866899

To do that you would need to edit the Code of your Theme.

The best is to create a Child Theme and copy the files you need (most likely header.php).

Then, you can insert a Content Template of your Choice anywhere in the Header where it can be displayed or used, using this function:
https://toolset.com/documentation/programmer-reference/views-api/#render_view_template

As an example, if you create a Content Template with ID 10, your code would look like this:

echo render_view_template( 10 );

This would then output the exact content of the Content Template.
The DOC Provides more details about the function.