How do i add a shortcode around this code:
<a rel="nofollow" href="<?php the_field('download_link',$taxonomy . '_' . $term_id); ?>"target="_blank">DOWNLOAD LINK 1</a>
I have already tried the code below. It doesn't actually activate the short code.
[sociallocker]
<a rel="nofollow" href="<?php the_field('download_link',$taxonomy . '_' . $term_id); ?>"target="_blank">DOWNLOAD LINK 1</a>
[/sociallocker]
In the Shortcode API, you can find a lots of examples how you can implement this. Here is a possible solution:
function download_shortcode( $atts, $content = null ) {
return '<a rel="nofollow" href="' . the_field('download_link',$atts['taxonomy'] . '_' . $atts['term_id']); . '" target="_blank">DOWNLOAD LINK 1</a>';
}
add_shortcode( 'download', 'download_shortcode' );
When used like this:
[download taxonomy=text1 term_id=text2]
The output would be:
<a rel="nofollow" href="/*The response from the function*/" target="_blank">DOWNLOAD LINK 1</a>
So, this function download_shortcode() should be in your theme's functions.php file, or in a separate plugin. The only problem here is that you can't pass php code there (inside, as content or as parameters), so you have to choose, add parameters to the shortcode (the taxonomy/term fields), or insert content between opening and closing [download][/download] shortcodes.
I'm not 100% clear on what you're trying to accomplish. Is this code in a template where you want to use the shortcode? If so, you need to use the do_shortcode
function, like so:
echo do_shortcode('[sociallocker]<a rel="nofollow" href="' . the_field('download_link',$taxonomy . '_' . $term_id) . '" target="_blank">DOWNLOAD LINK 1</a>[/sociallocker]');