PHP函数返回。嵌套函数
我知道有Wordpress StackExchange,但这是一个与PHP更相关的问题 我正在为Wordpress编写自己的短代码,它看起来像:PHP函数返回。嵌套函数,php,wordpress,function,return,shortcode,Php,Wordpress,Function,Return,Shortcode,我知道有Wordpress StackExchange,但这是一个与PHP更相关的问题 我正在为Wordpress编写自己的短代码,它看起来像: function myShortcode_shortcode() { return 'something'; } 此短代码显示简单的字符串“something” 问题是我想显示模板目录中的图像: <img src="<?php bloginfo('template_directory') ?>/images/myIma
function myShortcode_shortcode() {
return 'something';
}
此短代码显示简单的字符串“something”
问题是我想显示模板目录中的图像:
<img src="<?php bloginfo('template_directory') ?>/images/myImage.jpg" alt="" />
/images/myImage.jpg“alt=”“/>
我不知道怎么做
当我这样做时:
return '<img src="'. bloginfo('template_directory') .'/images/myImage.jpg" alt="" />';
返回“”;
脚本正在回显模板目录而不是图像
有什么想法吗?您可能需要将
/images/myImage.jpg“alt=”“/>
放在他自己的变量中,如
function shortcode(){
$shortcode = "<img src='". bloginfo('template_directory') ."/images/myImage.jpg' alt="" />"
return $shortcode;
}
function shortcode(){
$shortcode=“”
返回$shortcode;
}
希望这能有所帮助。问题是该函数是一个输出函数(用于模板)。您更需要。短代码部分与“模板目录”部分有什么关系?