Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP函数返回。嵌套函数_Php_Wordpress_Function_Return_Shortcode - Fatal编程技术网

PHP函数返回。嵌套函数

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

我知道有Wordpress StackExchange,但这是一个与PHP更相关的问题

我正在为Wordpress编写自己的短代码,它看起来像:

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;
} 
希望这能有所帮助。问题是该函数是一个输出函数(用于模板)。您更需要。

短代码部分与“模板目录”部分有什么关系?