gabby25 Posted January 6, 2021 Share Posted January 6, 2021 New to PHP, I wrote a shortcode to use in WP that outputs a nav bar with some icons. One will link to a url, one to a pop up plugin (through a class), and one a phone number. The shortcode will then look like this [footer-btn url="link here "]Name of Icon Here[/footer-btn] Right now when I put the short codes into word press, I get duplicates of the URL ones. function footer_btn_function($atts, $content){ extract( shortcode_atts( array( 'class' => '', 'phone' => '', 'url' => '' ), $atts ) ); if($class){ '<a class="text-link" href='.$class.'><img class="popmake-73310 footer-btn mobile" src="'.get_template_directory_uri().'/images/faq-mobile-white.png">'.$content.'</a>'; } if($phone){ $output .= '<a class="text-link" href="tel:'.$phone.'" target="_blank"><img class="footer-btn mobile" src="'.get_template_directory_uri().'/images/phone-mobile-white.png">'.$content.'</a>'; }; if($url){ $output .= '<a class="text-link" href="tel:'.$url.'" target="_blank"><img class="footer-btn mobile" src="'.get_template_directory_uri().'/images/vacation-rentals-mobile-white.png">'.$content.'</a>'; }; if($url){ $output .= '<a class="text-link" href="tel:'.$url.'" target="_blank"><img class="footer-btn mobile" src="'.get_template_directory_uri().'/images/chat-mobile-white.png">'.$content.'</a>'; }; return $output; } Quote Link to comment https://forums.phpfreaks.com/topic/311981-need-help-with-shortcodes-that-take-a-specific-url-or-input/ Share on other sites More sharing options...
requinix Posted January 6, 2021 Share Posted January 6, 2021 Well... according to the code, it does use $url twice. Is it duplicated because it's duplicated? Quote Link to comment https://forums.phpfreaks.com/topic/311981-need-help-with-shortcodes-that-take-a-specific-url-or-input/#findComment-1583678 Share on other sites More sharing options...
maxxd Posted January 6, 2021 Share Posted January 6, 2021 Beyond that, your code makes almost no semantic sense. $class indicates the value is a class name, but you're using it in an href attribute. $url should contain, well, a URL. You're using it in a href tel attribute (as requinix points out, twice). Make maintenance easier on yourself and try make variable names make some sort of sense given the data they're expected to contain. Quote Link to comment https://forums.phpfreaks.com/topic/311981-need-help-with-shortcodes-that-take-a-specific-url-or-input/#findComment-1583691 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.