WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 -->


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

        . $content .



add_shortcode('spoiler', 'spoiler');

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

share|improve this question
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">'


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


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

Your Answer


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.