w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Wordpress Nested Shortcode Help Please?

You have the right idea. I believe you would add the do_shortcode(); to the featrued_box function. Like so:

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>
    // HERE
    <p><?php echo do_shortcode($content); ?></p> // HERE
    </div>

<?php
    $content = ob_get_contents();
    ob_end_clean();
    return $content;
}

Note the do_shrotcode($content); part when echoing out the content.

Tidy Code

I took the liberty of tidying the code up a bit, to save using output buffering. Just create the html as a string and concatenate the variables/function outputs into it. Just personal preference really, so up to you! :)

I would also recommend using font-awesome with an <i class="fa fa-icon"></i> html tag instead of the <li class="fa fa-icon"></li> tag. An <li> tag being used outside of a <ul> tag would result in invalid html, where as a simple <i> tag would not.

function featured_box($atts, $content = null) {
    $sliderrandomid = rand();
    extract(shortcode_atts(array(
        "title" => '',
        'img'  => '',
        'pos' => '',
    ), $atts));

    $content = '
        <div class="featured-box ' . ($pos ? echo 'pos-'.$pos : null) .
'">
            <img class="featured-img" src="' . $img . '">
            <h4><span>' . $title .'</span></h4>
            <p>' . do_shortcode($content) . '</p>
        </div>
    ';

    return $content;
}

function addscFontAwesome( $atts ) {
    extract( shortcode_atts( array( 'type' => '', 'size' => ''),
$atts ) );

    // Note the <i> tag instead of <li>        
    $theAwesomeFont = '<i class="fa '.sanitize_html_class($type).'
'.sanitize_html_class($size).'"></i>';

    return $theAwesomeFont;
}




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.