How to use Shortcode in Worpdress
In current post we are going to show in simple way how to create register our own shortcode in wordpress and use it in wordpress website either in Page, post or widget area. To create our own shortcode we use Wordpress function add_shortcode and put it in your active theme fucntions.php file In following sample code we register our own shortcode numberboxadd_shortcode('numberbox','ls_fn_numberbox'); function ls_fn_numberbox($atts, $content = null) { extract(shortcode_atts(array('content' => '','fontsize' => '','color' => '#000','background'=>''), $atts)); ob_start(); ?> <span style="color: <?php echo $color ?> font-size: <?php echo $fontsize; ?>px; background:<?php echo $background ?> padding: 5px 12px"><?php echo $content; ?></span> <?php return ob_get_clean(); }Now you can use our register shortcode anywhere in Page, post editor area or in widget area by simple code format like
[numberbox content="101" fontsize="30" color="#fff" background="#0ac775"] and it will look like
0 Comments