Skip Navigation

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

This support ticket is created hace 5 años, 5 meses. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

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)

Etiquetado: 

Este tema contiene 3 respuestas, tiene 2 mensajes.

Última actualización por Nigel hace 5 años, 5 meses.

Asistido por: Nigel.

Autor
Mensajes
#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

Idiomas: Inglés (English ) Español (Español )

Zona horaria: 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

Idiomas: Inglés (English ) Español (Español )

Zona horaria: 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.