I have a simple custom shortcode that works fine inserting the attributes. However is it possible to put the standard lists within my shortcode and customise them for the output?

This is my input for the shortcode

[nr title="title" time="time" timec="c"]



This is my shortcode // Add Shortcode function custom_shortcode_nr( $atts , $content = null ) {

    // Attributes
    $atts = shortcode_atts(
            'time' => '15m',
            'timec' => 'h0m15',
            'title' => 'the title',

    // Return image HTML code
    return '<div id="nr"><h2>' . $atts['title'] . '</h2><ul class="details"><li><strong>Time ' . $atts['time'] . '</strong> (' . $atts['timec'] . ')</li></ul>' . $content . '</div>';
add_shortcode( 'nr', 'custom_shortcode_nr' );

This is the output functionality I would like to happen to unordered and ordered lists within my shortcode

<h3>title un</h3>
    <li class="unli">Unordered</li>

<h3>title or</h3>
    <li class="orli">Ordered</li>

Is this possible?


1 Answer 1


IMO you need to create individual shortcodes for UL, OL and LI to make it sample.

Shortcode for UL.

function shortcode_ul( $atts , $content = null )
     return '<ul>' . do_shortcode( $content ) .'</ul>';
add_shortcode( 'ul', 'shortcode_ul' );

Shortcode for LI

function shortcode_li( $atts , $content = null )
     return '<li>' . do_shortcode( $content ) .'</li>';
add_shortcode( 'li', 'shortcode_li' );


[ul] [li]Unordered[/li] [/ul]

It should output


Note: Add attributes as per requirement. E.g for CSS class <li> use attribute class. It'll be more flexible and extendable.

  • Thanks so much, is there any way to use just the normal [li] tag for each of them but call a different function depending on what type of custom [ul] or [ol] they are in? Commented Mar 21, 2018 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.