使用target =“_ blank”打开链接无法修复它

时间:2015-11-26 08:37:37

标签: php wordpress hyperlink

我想更改指向target =“_ blank”的链接(在新窗口或标签中打开),但可以修复它。我是一个傻瓜在PHP和我的尝试&误差方法不起作用。有人可以帮助我吗?

非常感谢你!

来自视差一主题(wordpress)的原始代码

<?php

if(!empty($parallax_one_contact_info_item_decoded)){    
    foreach($parallax_one_contact_info_item_decoded as $parallax_one_contact_item){
        if(!empty($parallax_one_contact_item->link)){
            echo '<div class="col-sm-4 contact-link-box col-xs-12">';
            if(!empty($parallax_one_contact_item->icon_value)){ 
                echo '<div class="icon-container"><span class="'.esc_attr($parallax_one_contact_item->icon_value).' colored-text"></span></div>';
            }
            if(!empty($parallax_one_contact_item->text)){
                echo '<a href="'.$parallax_one_contact_item->link.'" class="strong">'.$parallax_one_contact_item->text.' </a>';
            }
            echo '</div>';
        } else {
            echo '<div class="col-sm-4 contact-link-box  col-xs-12">';
            if(!empty($parallax_one_contact_item->icon_value)){
                echo '<div class="icon-container"><span class="'.esc_attr($parallax_one_contact_item->icon_value).' colored-text"></span></div>';
            }
            if(!empty($parallax_one_contact_item->text)){
                if(function_exists('icl_translate')){
                    echo '<a href="" class="strong">'.icl_translate('Contact',$parallax_one_contact_item->id.'_contact',esc_attr($parallax_one_contact_item->text)).'</a>';
                } else {
                    echo '<a href="" class="strong">'.esc_attr($parallax_one_contact_item->text).'</a>';
                }
            }
            echo '</div>';
        }
    }
}
?> 

2 个答案:

答案 0 :(得分:1)

只需在锚标记中添加target="_blank"即可。例如:

echo '<a target="_blank" href="'.$parallax_one_contact_item->link.'" class="strong">'.$parallax_one_contact_item->text.' </a>';

答案 1 :(得分:0)

试试这个:

<?php

if(!empty($parallax_one_contact_info_item_decoded)){    
    foreach($parallax_one_contact_info_item_decoded as $parallax_one_contact_item){
        if(!empty($parallax_one_contact_item->link)){
            echo '<div class="col-sm-4 contact-link-box col-xs-12">';
            if(!empty($parallax_one_contact_item->icon_value)){ 
                echo '<div class="icon-container"><span class="'.esc_attr($parallax_one_contact_item->icon_value).' colored-text"></span></div>';
            }
            if(!empty($parallax_one_contact_item->text)){
                echo '<a target="_blank" href="'.$parallax_one_contact_item->link.'" class="strong">'.$parallax_one_contact_item->text.' </a>';
            }
            echo '</div>';
        } else {
            echo '<div class="col-sm-4 contact-link-box  col-xs-12">';
            if(!empty($parallax_one_contact_item->icon_value)){
                echo '<div class="icon-container"><span class="'.esc_attr($parallax_one_contact_item->icon_value).' colored-text"></span></div>';
            }
            if(!empty($parallax_one_contact_item->text)){
                if(function_exists('icl_translate')){
                    echo '<a target="_blank" href="" class="strong">'.icl_translate('Contact',$parallax_one_contact_item->id.'_contact',esc_attr($parallax_one_contact_item->text)).'</a>';
                } else {
                    echo '<a target="_blank" href="" class="strong">'.esc_attr($parallax_one_contact_item->text).'</a>';
                }
            }
            echo '</div>';
        }
    }
}
?> 

注意:在每个超链接中添加了target="_blank"