【发布时间】:2020-06-30 20:09:53
【问题描述】:
我正在修改一个 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 属性。有人可以解释这一点并就如何使这项工作提出建议吗?谢谢!
【问题讨论】:
标签: php html wordpress shortcode