Skip Navigation

[Résolu] How to include a custom Shortcode in Layout template

This support ticket is created Il y a 4 années et 11 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

Marqué : 

This topic contains 3 réponses, has 2 voix.

Last updated by Nigel Il y a 4 années et 10 mois.

Assisted by: Nigel.

Auteur
Publications
#1249343

Hi,

I have created a custom shortcode by adding code in theme's function file. It is working fine when I use shortcode on a standalone page.

However when I try to add it on a layout template for a custom post, it does not work. Nothing is displayed. Can you help me on this?

#1249401

Nigel
Supporter

Languages: Anglais (English ) Espagnol (Español )

Timezone: Europe/London (GMT+01:00)

I suspect the problem is in the code of the shortcode itself, perhaps because the context is different than you anticipated when writing the shortcode.

You can verify that shortcodes should be parsed and output within a Layouts template by registering a [dummy] shortcode with the following code and inserting the shortcode in your template:

add_shortcode('dummy', function () {

    return "Dummy text";
});

If you share the code of your shortcode I might be able to spot the problem.

#1262113

Hi,

As I mentioned, shortcode is working fine when included on a separate page but not working in a layout template. My first question is whether can I include a shortcode within a layout template or not?

#1262117

Nigel
Supporter

Languages: Anglais (English ) Espagnol (Español )

Timezone: Europe/London (GMT+01:00)

Screenshot 2019-06-07 at 10.23.52.png
Screenshot 2019-06-07 at 10.24.53.png

Shortcodes work in Layouts templates, yes.

In the screenshot you can see the result of the test I described in my first reply.

The problem will be with your shortcode code. You can try the same test to verify.

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