0

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?

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

2

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.

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.