Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress twig template shortcode not displayed

I'm using Symfony Twig template with Wordpress, everything runs fine except that I can't get any shortcode to be displayed in a page template.

I'm trying to display a contact form with Contact form 7 plugin.

The shortcode is something like [contact-form-7 id='1234' title='Contact'] Even Wordpress default shortcode are not working.

Here is my code for page template:

{% extends 'base.html.twig' %}

{% block content %}
    <h1>{{ post.post_title }}</h1>

    <div class="entry">
        {{ post.post_content|raw }}
    </div>
{% endblock %}

If I replace

{{ post.post_content|raw }}

by this

{{ wp.do_shortcode('[contact-form-7 id="1234" title="Contact"]') }}

I can see the contact form. But I don't want to write the shortcode in my template file.

Thanks for your help

like image 642
user3480375 Avatar asked Dec 16 '22 00:12

user3480375


1 Answers

Try this

{{  post.post_content|shortcodes }}

And with custom fields

{{ customfield|shortcodes }}
like image 71
Malav Panchal Avatar answered Jan 04 '23 18:01

Malav Panchal