Php 如何在wordpress中使用函数内部函数创建短代码
在我的theme function.php中,我试图为myHeader、myFooter等添加短代码 在myHeader(),myFooter()函数中,我添加了另一个函数,如fn_1(),fn_2(),fn_3()等。这些函数将每周或每月更改 是否可以调用下面所述的短代码Php 如何在wordpress中使用函数内部函数创建短代码,php,wordpress,function,shortcode,Php,Wordpress,Function,Shortcode,在我的theme function.php中,我试图为myHeader、myFooter等添加短代码 在myHeader(),myFooter()函数中,我添加了另一个函数,如fn_1(),fn_2(),fn_3()等。这些函数将每周或每月更改 是否可以调用下面所述的短代码 function myHeader(){ fn_1(); //fn_2(); } function myFooter(){ fn_2(); // fn_3(); } add_shortcode(
function myHeader(){
fn_1();
//fn_2();
}
function myFooter(){
fn_2();
// fn_3();
}
add_shortcode('myFooter', 'myHeader');
add_shortcode('myFooter', 'myFooter');
function fn_1(){
return 'something for 1';
}
function fn_2(){
return 'something for 2';
}
function fn_3(){
return 'something for 3';
}
在我的帖子中,我将我的短代码称为[myHeader]和[myFooter]如果可能,您只需要在短代码方法中返回一些内容。短代码函数也需要一些变量,尽管实际上不必使用它们 例如
如果您要传递$atts或不传递$atts,则需要$atts来创建短代码。感谢您的回复,必须添加参数($atts,$content=null),因为我没有将任何参数传递给myHeader(),myFooter函数,它只是根据我的经验返回一些字符串,最好添加参数。谢谢您的尝试,如果这项工作能作为一个答案
function myHeader($atts, $content = null){
$temp = fn_1();
return $temp;
}