WordPress.org

Ready to get started?Download WordPress

Forums

Hiding text in a post (5 posts)

  1. vyrlson
    Member
    Posted 4 years ago #

    At some point in time following an initial post I want to be able to edit it in such a way that the edited portion will be hidden from unauthorized readers. What's the easiest way to accomplish this?

  2. s_ha_dum
    Member
    Posted 4 years ago #

    Shortcodes maybe.

  3. vtxyzzy
    Member
    Posted 4 years ago #

    Here is a short bit of code to add to the end of your functions.php. It provides the [mm-hide-text] shortcode. All text between [mm-hide-text] and [/mm-hide-text] will be hidden from all but Admins.

    <?php // [mm-hide-text]some text here[/mm-hide-text]
    function mm_hide_text_func($atts, $content=null) {
       extract(shortcode_atts(array('noatts' => 'Unknown' ), $atts));
       $output = '';
       if (!is_null($content) && current_user_can('administrator')) {
          $output = $content;
       }
    
       return $output;
    }
    add_shortcode('mm-hide-text', 'mm_hide_text_func');
    ?>
  4. vyrlson
    Member
    Posted 4 years ago #

    Thanks a lot for this. I'll try it out.

  5. vtxyzzy
    Member
    Posted 4 years ago #

    You are welcome. If it works for you, please use the dropdown at top right to mark this topic 'Resolved'.

Topic Closed

This topic has been closed to new replies.

About this Topic