Wordpress twig template shortcode not displayed

2019-07-29 11:03发布

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

3条回答
别忘想泡老子
2楼-- · 2019-07-29 11:43
{% filter shortcodes %}
    {{ wp.do_shortcode(' [email-subscribers') }}
{% endfilter %}

but the only HTML displayed not displayed Email subscribers form.

查看更多
孤傲高冷的网名
3楼-- · 2019-07-29 11:50

Try this

{{  post.post_content|shortcodes }}

And with custom fields

{{ customfield|shortcodes }}
查看更多
时光不老,我们不散
4楼-- · 2019-07-29 12:00

One of the following should work!

{{ wp.do_shortcode( post.post_content) }}

or,

{{ wp.do_shortcode( post.post_content)|raw }}

or ,

{{ wp.do_shortcode( post.post_content|raw ) }}

or

{{ wp.do_shortcode( post.post_content|raw )|raw }}

Updated

Working Code Is :

{{ wp.do_shortcode( post.post_content)|raw }}

查看更多
登录 后发表回答