0

Is there a way I can add a custom title & subtitle to this shortcode function?

function spoiler( $atts, $content = null ) {
return '<div class="moreinfo">

    <h3 class="click drop subtitle">

        <!-- title & subtitle go here -->

    </h3>

    <div class="morecontent"><p>'

        . $content .

    '</p></div><!--/.morecontent-->

</div><!--/.moreinfo-->';
}

add_shortcode('spoiler', 'spoiler');

Obviously the title & subtitle would go there the comment is in the h3 tag.

0
function spoiler( $atts, $content = NULL ) {
    extract( shortcode_atts( array(
        'title'    => 'default title',
        'subtitle' => 'default subtitle',
    ), $atts ) );

    return '<div class="moreinfo"><h3 class="click drop subtitle">'

    .'Title:'.$title.'Subtitle:'.$subtitle.

    '</h3><div class="morecontent"><p>'

    .$content.

    '</p></div><!--/.morecontent--></div><!--/.moreinfo-->';
}
add_shortcode( 'spoiler', 'spoiler' );

//[spoiler title='title' subtitle='subtitle']content[/spoiler]

Docs: add_shortcode, extract

That should allow you to display the title and subtitle by applying them as attributes. You could, if you liked, do processing on content and use some sort of divider (say || or something that would never be used in the text) and do an explode() on the content based on that divider...your call.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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