Wordpress短代码仅接受默认属性

时间:2018-04-04 09:33:17

标签: php wordpress shortcode

问题在于,当我将短代码插入到PageBuilder时,只会将默认值排除在外。代码是这样的:

function Insert_Download($attr) {
    $z = shortcode_atts(array(
        'link_file' => 'xxxx',
        'link_class' => 'e-countries__link',
        'svg_path' => '#download',
        'svg_class' => 'e-countries__link-svg'
    ), $attr);
    $download = '<a class="'. esc_attr($z["link_class"]) . '" href="'. get_template_directory_uri(). '/' . esc_attr($z["link_file"]) . '" download>' . esc_html__('Download', 'fbstax-theme') . '<svg class="' . esc_attr($z["svg_class"]) .'" style="width:20px; height: 20px; margin-left: 20px"><use xlink:href=' . get_template_directory_uri(). '/img/svg/sprite.svg' . esc_attr($z["svg_path"]) . '></use></svg>'.'</a>';
    return $download;
}
add_shortcode( 'InsertDownload', 'Insert_Download' );

所以在我的PageBuilder中我插入了这个

[InsertDownload linkPath='downloads/poland/code_of_commercial_companies_in_poland.pdf']

但结果属性href看起来像这样:

href="http://my.localclean.my/wp-content/themes/fbstax-theme/xxxx"

有什么问题?

1 个答案:

答案 0 :(得分:0)

将linkPath替换为link_file

[InsertDownload link_file='downloads/poland/code_of_commercial_companies_in_poland.pdf']