Adding a Shortcode to a Button
-
Hi there, is there any way to link a shortcode from the php to a button wordpress?
I just basically want the shortcode to be executed with a button click.I’ve also tried using:
<a href="<?php get_download_file(); ?>" class="btn" > CLICK TO OPEN SHORTCODE</a>
PHP:
add_shortcode('get_download_file', 'get_download_file'); function get_download_file() { $download_file = sanitize_text_field($_GET['dl']); if (checkRootDomain($download_file)) { // Domain is nuspire.com return '<a href="'.$download_file.'" target="_blank">Download</a>'; } else { // Domain is not nuspire.com } } function checkRootDomain($url) { if (!preg_match("~^(?:f|ht)tps?://~i", $url)) { $url = "?https://" . $url; } $domain = implode('.', array_slice(explode('.', parse_url($url, PHP_URL_HOST)), -2)); if ($domain == 'nuspire.com') { return true; } else { return false; } }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Adding a Shortcode to a Button’ is closed to new replies.