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.

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

2 Answers

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
    
Thank you, that helps! Regards Klaus –  user25236 Dec 26 '12 at 20:04
add comment

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()
{
    add_meta_box(
        't5_extra',
        'Extra',
        't5_extra_metabox_callback',
        NULL, // screen
        'normal',
        'default'
    );
}
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 );
    wp_editor(
        $content,
        '_t5_extra_box',
        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__ )
    )
    {
        return;
    }

    if ( isset ( $_POST['_t5_extra_box'] ) )
        update_post_meta( $post_id, '_t5_extra_box', $_POST['_t5_extra_box'] );
    else
        delete_post_meta( $post_id, '_t5_extra_box' );
}
share|improve this answer
    
Very helpful, thanks and regards Klaus. –  user25236 Dec 26 '12 at 20:15
add comment

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.