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

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
up vote 2 down vote accepted
add_shortcode( 'hidetext', 'my_hidetext_shortcode' );
function my_hidetext_shortcode( $atts, $content = '' ) {
    if( is_single() )
        return $content;

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;

tested and works.

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.