我正在修改一个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属性,但不能修改链接的目标属性。有没有人能解释一下这一点,并提供一个如何使其工作的建议?谢谢!
发布于 2020-03-20 14:33:53
我们发现了两个错误
我们已经解决并更新了如下代码,请替换下面的函数以及一个短代码。
函数如下:
// 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]
我希望它能为你工作,因为我们已经尝试过了,它对我也是有效的。
谢谢!
https://stackoverflow.com/questions/60761448
复制相似问题