Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted
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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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