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 any shortcode or a plugin that will add new quicktag, like this example:

[hidemytext]some hidden text[/hidemytext]

and any text inside those tag is hidden from the post or from the page.

Thanks and regards

share|improve this question

Simple answer:

add_shortcode( 'hidemytext', '__return_false' );

But shortcodes should never be used like that. Imagine what happens when the plugin or theme with that shortcode is turned off: everyone can see the content now. This is not very user friendly.

So switch the logic: show nothing or the bare shortcode tag by default, show the content only if the shortcode handler is active. Store the hidden content in a simple metabox:

enter image description here

To do that, add a metabox with an editor and show its content per shortcode:

add_shortcode( 'extra',  't5_extra_content' );
add_action( 'add_meta_boxes_post', 't5_register_extra_metabox' );
add_action( 'save_post', 't5_save_shortcode_box', 10, 2);

function t5_extra_content( $attributes, $content = '' )
    $args = shortcode_atts( array ( 'cap' => 'edit_posts' ), $attributes );

    if ( current_user_can( $args['cap'] ) )
        return wpautop(
            get_post_meta( get_the_ID(), '_t5_extra_box', TRUE )
            . $content

function t5_register_extra_metabox()
        NULL, // screen
function t5_extra_metabox_callback( $post )
    $nonce = wp_create_nonce( __FILE__ );
    echo "<input type='hidden' name='t5_extra_box_nonce' value='$nonce' />";
    $content = get_post_meta($post->ID, '_t5_extra_box', TRUE );
        array (
            'textarea_rows' => 10,
            'media_buttons' => FALSE,
            'teeny'         => TRUE,
            'tinymce'       => TRUE
function t5_save_shortcode_box( $post_id )
    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE
        or ! isset ( $_POST['post_type'] )
        or 'post' !== $_POST['post_type']
        or ! current_user_can( 'edit_post', $post_id )
        or ! wp_verify_nonce( $_POST[ 't5_extra_box_nonce' ], __FILE__ )

    if ( isset ( $_POST['_t5_extra_box'] ) )
        update_post_meta( $post_id, '_t5_extra_box', $_POST['_t5_extra_box'] );
        delete_post_meta( $post_id, '_t5_extra_box' );
share|improve this answer

You really should be able to work this out from the examples in the Codex.

function hide_text( $atts,$content) {
  return ''; // returns nothing
  // or
  return '<!-- '.$content.' -->'; // returns an html commented version of your text
add_shortcode( 'hidemytext', 'hide_text' );
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.