我正在修改wordpress主题。我希望能够使用短码在新标签页中打开链接。
// add shortcode for About Our Charity Section
function theme_about_charity($atts, $content = null){
extract(shortcode_atts(array(
'title' => '',
'icon' => '',
'link' => '',
'last' => '',
'newTab' => ''
),$atts));
return ' <div class="about-box" id="'.(($last == 'yes') ? 'last' : '').'">
<h3><i class="fa fa- '.$icon.'"></i><a href="'.$link.'" target="'.($newTab == 'yes')? '_blank' : '_self' . '">' .$title.'</a></h3>
<p>'.$content.'</p>
</div>';
}
add_shortcode('about_charity','theme_about_charity');
当用户创建简码时:
[about_charity icon="icon" title="title" link="#" newTab="yes" ]lorem ipsum[/about_charity]
现在代码只是在我的网页上打印“ _blank”。
该代码可用于修改div的id属性,但不能修改链接的target属性。有人可以解释一下并提出如何进行这项工作的建议吗?谢谢!
我们发现了两个错误
我们已解决并更新了以下代码,请替换以下功能以及简码。
功能如下:
// add shortcode for About Our Charity Section
function theme_about_charity($atts, $content = null){
extract(shortcode_atts(array(
'title' => '',
'icon' => '',
'link' => '',
'last' => '',
'newtab' => ''
),$atts));
return '<div class="about-box" id="'.(($last == 'yes') ? 'last' : '').'">
<h3><i class="fa fa- '.$icon.'"></i><a href="'.$link.'" target="'.(($newtab == 'yes') ? '_blank' : '_self') . '">' .$title.'</a></h3>
<p>'.$content.'</p>
</div>';
}
add_shortcode('about_charity','theme_about_charity');
以下短代码:
[about_charity icon="icon" title="title1" link="https://www.google.com" newtab="yes" ]lorem ipsum[/about_charity]
我希望它对您有用,因为我们已经尝试过并且对我有用。
谢谢!