Php 如何在另一个短代码函数中编写do短代码函数
我在这个函数中有一个带有标签[form edit]的自定义短代码,我需要执行一个插件短代码,例如[form id=“10”]。下面给出的是我的非工作代码Php 如何在另一个短代码函数中编写do短代码函数,php,wordpress,shortcode,Php,Wordpress,Shortcode,我在这个函数中有一个带有标签[form edit]的自定义短代码,我需要执行一个插件短代码,例如[form id=“10”]。下面给出的是我的非工作代码 add_shortcode('form-edit', 'form_edit_function'); function form_edit_function(){ $fid = $_GET['fid']; echo do_shortcode('[Form id="'.$fid.'"]'); } 如何使之成为可能?请提供帮助我认为
add_shortcode('form-edit', 'form_edit_function');
function form_edit_function(){
$fid = $_GET['fid'];
echo do_shortcode('[Form id="'.$fid.'"]');
}
如何使之成为可能?请提供帮助我认为问题在于在函数中使用$\u GET,因为在调用\u内容或您正在添加的任何函数时,这可能不可用
function form_edit_function( $atts , $content = null ) {
// Extra attributes into variables
extract( shortcode_atts(
array(
'fid' => '' // the default value if not passed
), $atts )
);
$html = do_shortcode('[Form id="' . $fid . '"]');
// store in variable and return other echo will not
// put it in the correct place within your content
return $html;
}
// Use in post content or other places as [form-edit fid="1][/form-edit]
add_shortcode( 'form-edit', 'form_edit_function' );
通常,短代码通过RETURN语句而不是ECHO发送其输出。如果您回显它,它将在Wordpress请求的正常操作顺序之外发送。它将被插入到输出的标题中,甚至可能不可见。另外,您知道这里有两个短代码,“表单编辑”和“表单”,对吗?对于一个短代码来说,两者都是非常糟糕的名字。短代码名称区分大小写。你确定你的第二个短文是“形式”而不是“形式”吗?这似乎是错误的。我认为$\u GET变量将在全球范围内可用。我们可以稍微编辑一下第一句话吗?这没有什么意义。可能:“我有一个自定义短代码,[表单编辑]。在这个短代码中,我需要另一个短代码的输出。”