I am fairly competent with WordPress but I am trying to make things a little more complicated to stretch myself and I'm trying to create custom short codes. I have successfully managed to create two separate short codes; 1) featured_box 2) awesome_font_icon.
These two short codes work perfectly as single entities but when trying to nest the short codes e.g.) [featured_box][icon type="fa-bullhorn"][/featured_box]
the [icon type="fa-bullhorn"]
displays literally just that text and not the desired Awesome Font Icon.
I know that you have to add do_shortcode()
to the script but I am not entirely sure where to put the do_shortcode()
and to which short code, whether I place this into the featured_box or the awesome_font short code.
I have placed both scripts below.
Featured Box PHP:
function featured_box($atts, $content = null) {
$sliderrandomid = rand();
extract(shortcode_atts(array(
"title" => '',
'img' => '',
'pos' => '',
), $atts));
ob_start();
?>
<div class="featured-box <?php if($pos) echo 'pos-'.$pos; ?>">
<img class="featured-img" src="<?php echo $img; ?>">
<h4><span><?php echo $title; ?></span></h4>
<p><?php echo $content; ?></p>
</div>
<?php
$content = ob_get_contents();
ob_end_clean();
return $content;
}
add_shortcode("featured_box", "featured_box");
Awesome Font Shortcode:
add_action( 'wp_enqueue_scripts', 'load_fontawesome_style', 999 );
function load_fontawesome_style() {
wp_register_style( 'font-awesome', 'http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css' );
wp_enqueue_style( 'font-awesome' );
}
function addscFontAwesome( $atts ) {
extract( shortcode_atts( array( 'type' => '', 'size' => ''), $atts ) );
$theAwesomeFont = '<li class="fa '.sanitize_html_class($type).' '.sanitize_html_class($size).'"></li>';
return $theAwesomeFont;
}
add_shortcode('icon', 'addscFontAwesome');
I have looked across the net and found various different tutorials etc but have not been successful as of yet. As I say, everything works perfectly, just not together.
I do appreciate nested short codes have been covered to death; all I have found was very generic and I don't think I'm guide that good at PHP to understand where to put it.