How can I enable shortcodes on a custom post type that doesn't use the_content()
or get_the_content()
?
In the template file it uses
<?php echo nl2br( $post->post_content ); ?>
to get the content from the backend like any other post or page would. I have tried using
<?php echo do_shortcode(get_post_field('post_content', $postid)); ?>
which works but the shortcode itself is still displaying for example:
[gallery columns="4" link="file" ids="1,2,3,4"]
displays above the gallery photos.
How can I enable shortcodes on a custom post type that doesn't use the_content()
or get_the_content()
?
In the template file it uses
<?php echo nl2br( $post->post_content ); ?>
to get the content from the backend like any other post or page would. I have tried using
<?php echo do_shortcode(get_post_field('post_content', $postid)); ?>
which works but the shortcode itself is still displaying for example:
[gallery columns="4" link="file" ids="1,2,3,4"]
displays above the gallery photos.
Share Improve this question edited Jul 1, 2018 at 10:33 Max Yudin 6,3882 gold badges26 silver badges36 bronze badges asked Jul 1, 2018 at 6:01 PeterPeter 292 silver badges7 bronze badges 3- 1 And why doesn’t it use the_content? – Krzysiek Dróżdż Commented Jul 1, 2018 at 6:04
- I do not know why it doesn't use the_content. This is a plugin from WordPress Repository - All In One Video Gallery. – Peter Commented Jul 2, 2018 at 6:20
- Then the plugin appears to have been built in such a way that doesn't support shortcodes. You will need to check with the author if there's a workaround. – Jacob Peattie Commented Jul 2, 2018 at 11:26
4 Answers
Reset to default 2I had similar problem because I was rendering content like this:
echo get_the_content();
Instead of:
the_content();
The 2nd function must include the shortcode filter.
Shortcodes really should run in custom post types. Essentially a custom post type is a post. So it sounds like there is a problem filtering shortcodes somewhere.
What is likely happening is that you are using get_the_content() rather than the_content() which doesn't filter. Where and how are you displaying the content for the custom post type?
If this is the case, please use get_the_content() function in this way to apply appropriate filtering.
<?php apply_filters('the_content',get_the_content( $more_link_text,
$stripteaser, $more_file )) ?>
Visit this link for more detail about your Problem
wpmudev
Use apply_filters()
to let WordPress process the shortcodes in your content.
<?php echo apply_filters('the_content', $post->post_content); ?>
For my particular situation the answer was to replace <?php echo nl2br( $post->post_content ); ?>
with <?php echo $content; ?>
which allowed all shortcodes to work as expected.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744692895a4588315.html
评论列表(0条)