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.

I'm looking for a shortcode similar to this:

[hidetext]some text to hide[/hidetext]

Then what will happen is that the the tag will hide the text from any page that isn't the Single Post page. Only on the Single Post Page will the [hidetext] show. How can I do something like this?

share|improve this question

2 Answers 2

up vote 2 down vote accepted
add_shortcode( 'hidetext', 'my_hidetext_shortcode' );
function my_hidetext_shortcode( $atts, $content = '' ) {
    if( is_single() )
        return $content;
    else
        return;
}

Docs: add_shortcode(), is_single()

Solution is untested.

share|improve this answer

A slight modification on the function above. You'll want to use is_singular('post') instead, unless you also want to target other areas

add_shortcode( 'hidetext', 'rkv_hidetext_shortcode' );

function rkv_hidetext_shortcode( $atts, $content = null) {
    if( is_singular('post') )
        return $content;
    else
        return;
}

tested and works.

share|improve this answer

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.