Lets say I have a theme option or custom postmeta text area. Now I want to execute multiple shortcodes, general texts, images etc.
What will be best practice and why?
Option 1:
$content = //my text area data;
echo apply_filters('the_content', $content);
Option 2:
$content = //my text area data;
echo do_shortcode($content);
Kindly explain me which one will be best practice and why.
EDIT
Let me describe the scenario in details. I develop themes for clients with their requirements. Sometimes, I need to add post meta on post/pages/custom post types, so that they can add shortcodes (slider, contact form etc) or just a simple text. It's a text filed.
To make the shortcode working, I use option 1. Now, I heard from someone that this is a wrong way, and I should use do_shortcode. But they did not give me an explanation of why it's wrong way. That's why I am asking.
This whole process can be done in the default text editor of wp. But I need to create those options for template specific usage, that's what my clients want.
可以说我有一个主题选项或自定义的postmeta文本区域.现在,我要执行多个短代码,常规文本,图像等.
最佳做法是什么?为什么?
选项1:
选项2:
请向我解释哪种方法是最佳实践,为什么?
编辑
让我详细描述该方案.我根据客户的要求开发主题.有时,我需要在帖子/页面/自定义帖子类型上添加帖子元,以便他们可以添加短代码(滑块,联系表格等)或仅添加简单文本.这是文本.
为使短代码有效,我使用了选项1 .现在,我从某人那里听说这是错误的方法,我应该使用
do_shortcode
.但是他们没有给我解释为什么这是错误的方式.这就是为什么我问.这整个过程可以在wp的默认文本编辑器中完成.但是我需要为模板的特定用途创建这些选项,这是我的客户想要的.