File download shortcode

Hello
I am using the file download shortcode:
for example:
[s2File download=“example-file.zip” /]

in the front end it outputs the full URL to the file.
How can this rather be a link to the file?
Meaning that in the front end it will output it inside a <a href> tag?

Thanks
Dan

Just treat it like any other hyperlink:
<a href="[s2File download='example-file.zip' /]">link text</a>

1 Like

Thanks
I guess the issue was with the double quotation marks

Dan

Yes. You can’t have double quotes inside double quotes, or single quotes inside single quotes.

I found the following functions code to be helpful in automatically creating the link within the shortcode. So you would write [s2Link name=“Name of file displayed” download="/location.pdf" target="_blank" /] and you would automatically link the NAME with the proper url.

function eskeinet_s2Link_shortcode($atts,  $content = null){
extract(shortcode_atts(
    array('download' => false, 
        'download_key' => 0), 
    $atts
));

$return_string = '';
if(!$content){
    $content = "Download File";
}
if($download && $download_key){
    $return_string = '<a href="'.do_shortcode('[s2File download="'.$download.'" download_key="true" /]').'">'.$content.'</a>';
}elseif($download){
    $return_string = '<a href="'.do_shortcode('[s2File download="'.$download.'" /]').'">'.$content.'</a>';
}
return $return_string;
}
add_shortcode('s2Link', 'eskeinet_s2Link_shortcode');
1 Like