Skip Navigation

[Resolved] How to include a custom Shortcode in Layout template

This support ticket is created 5 years, 7 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
- 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+00:00)

This topic contains 3 replies, has 2 voices.

Last updated by Nigel 5 years, 6 months ago.

Assisted by: Nigel.

Author
Posts
#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: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00: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: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00: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.