Html WordPress快捷码添加属性
我正在为WP编写一个短代码函数。在函数中,我有$content(在本例中是一个图像)。我需要能够向该内容添加几个属性并以字符串形式返回,如下所示:Html WordPress快捷码添加属性,html,string,wordpress,shortcode,Html,String,Wordpress,Shortcode,我正在为WP编写一个短代码函数。在函数中,我有$content(在本例中是一个图像)。我需要能够向该内容添加几个属性并以字符串形式返回,如下所示: function Shortcode( $atts, $content=null ){ if(!is_null($content){ return '<div class="wrapper">'. $content .'</div>' } } 函数短码($atts,$content=null){ 如果
function Shortcode( $atts, $content=null ){
if(!is_null($content){
return '<div class="wrapper">'. $content .'</div>'
}
}
函数短码($atts,$content=null){
如果(!为null($content){
返回“”。$content。“”
}
}
目前,只有图像得到了回吐,但我需要以某种方式修改它,并在将其添加到上面的字符串之前添加一些属性
我需要这样做:
function Shortcode( $atts, $content=null ){
if(!is_null($content){
// CONVERT $CONTENT TO STRING
$content_html=somefunction($content)
echo $content_html; // <img src='....' />
return '<div class="wrapper">'. $content_html .'</div>'
}
}
函数短码($atts,$content=null){
如果(!为null($content){
//将$CONTENT转换为字符串
$content\u html=somefunction($content)
echo$content_html;//
返回“”。$content\u html。“”
}
}
变量$content
将始终包含图像标记?显示您的示例输出能否显示您当前拥有的功能代码以及当前接收的输出。您应该能够将$content
设置为数组,只需添加到数组中,但我们需要查看当前代码。我已经更新了问题..n我不确定这是否有帮助…基本上我正在尝试“编辑”$内容,但不知道如何首先将其转换为与html等效的字符串(