/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php /* Short code [a href="pageId" class"clasName"]link[/a] */ /*If you check “add paragraphs automatically†on the widget, WordPress will apply the autop filter — the one that turns your line breaks into paragraph and break tags. If a shortcode is on its own line, it would normally get wrapped in a paragraph tag. The first line prevents that from happening. thanks to http://sillybean.net/2010/02/using-shortcodes-everywhere/ */ add_filter( 'widget_text', 'shortcode_unautop'); //Add shortcode functionality to widgets add_filter('widget_text', 'do_shortcode'); function a_func($atts, $content) { 'href' => ' ', 'class' => ' ', ), $atts)); $theLink = '<a class="'. $class .'" href="'. get_permalink($href) .'">'. $content .'</a>'; return "{$theLink}"; } add_shortcode('a', 'a_func'); ?>