Shortcodes
Because giving people HTML and Php to edit themselves is just wrong?
It’s much easier to tell them this:
1 2 3 4 | [links] [link url="http://www.google.com" name="Google"] [link url="http://www.apple.com" name="Apple"] [/links] |
And heres what makes that all possible:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | function links_shortcode_callback( $atts, $content=null ){ //Set a blank value for default $return = ""; //If there is content between the shortcodes then add our wrapping tags if($content){ $return = '<ul class="links">' //Nested shortcodes are not processed by default be sure to make this call if you want to process nested shortcodes $return .= do_shortcode($content); $return .= '</ul>'; } //Never echo output from a shortcode function return $ret; } function link_shortcode_callback( $atts ){ //Get the attributes and filter out unwanted attributes $a = shortcode_atts( array( 'url' => 'No Website', 'name' => 'No Name'), $atts ); //Build HTML $return = "<li><span class='link'>"; $return .= "<a href=\"".$a['url']."\">". $a['name']. "</a>"; $return .= '</span></li>'; //Again, return NOT echo: return $return; } // Finally, tell WordPress about our shortcodes add_shortcode( "links", "links_shortcode_callback" ); add_shortcode( "link", "link_shortcode_callback" ); |
