Options for Teasers for Restricted Content

In another tutorial, we showed how to create a teaser for restricted content. That basic guide is worth reading before you dive into these more advanced options.

In this tutorial, we'll show you all the configuration options for your Teasers.

You will find these settings by going to Permissions > Settings > Teaser in your WordPress site.


RSS Feeds

WordPress automatically produces RSS feeds for all your content. It's not always true that RSS feeds have the same permissions as your content, so some of it may accidentally become visible. With this feature, you can control what displays in your RSS feed for private content.

Rss Block
Rss Block

Custom Fields

By default, PublishPress Permissions will automatically hide the “Featured Image” for posts that users are now allowed to access. You can make the image visible by unchecking this box:

Custom Fields Permission
Custom Fields Permission

Hidden Content Teaser

You have five choices for teasers. These will show when users try to access restricted content that they are not allowed to access.

Teaser Choices
Teaser Choices

No Teaser

If you choose “No Teaser”, WordPress will pretend that this content does not exist. All visitors will see is a “Nothing Found” message. They won't even see the URL of the post in their browser bar.

Fixed Teaser

This will show two things to users who don't have permission to read the post:

  1. The Title of the Post
  2. The message that you enter in the “Teaser Text” box. The default text is “Sorry, you don't have access to this content. Please log in or contact a site administrator for help.”
Teaser Text
Teaser Text

Excerpt as Teaser

This will show two things to users who don't have permission to read the post:

  1. The Title of the Post
  2. The message that you enter in the “Excerpt” box. If that does not exist for a post, the Teaser Text > Content > “replace with” settings are used for teaser text instead.

Excerpt or Pre-More as Teaser

This will show two things to users who don't have permission to read the post:

  1. The Title of the Post
  2. The message you enter in the “Excerpt” box. The Excerpt is empty, it will then look to show any content before the “Read More” line in your text. If neither of those exist for a post, the Teaser Text > Content > “replace with” settings are used for teaser text instead.

Excerpt, Pre-More, or first 50 chars

This will show two things to users who don't have permission to read the post:

  1. The Title of the Post
  2. The message you enter in the “Excerpt” box. The Excerpt is empty, it will then look to show any content before the “Read More” line in your text.  If neither exists for the post, the first 50 characters are displayed.

The 50 character limit can be changed by setting this constant in your wp-config.php file:

define('PP_TEASER_NUM_CHARS', 100);  // set to desired number of characters (any value)

Teasers for Custom Post Types

It is possible to create teasers for any post type. Copy the following code into your theme's functions.php file. You will need to adjust the ‘my_custom_type' identifier:

                        add_filter( 'presspermit_teaser_text', 'my_custom_teaser_text', 10, 5 );

                        /*
                         * adjustment_type: replace, prefix or suffix
                         * post_part: content, excerpt or name
                        */
                        function my_custom_teaser_text( $text, $adjustment_type, $post_part, $post_type, $is_anonymous ) {
                            switch ( $post_type ) {
                                case 'page':
                                    if ( ( 'content' == $post_part ) && ( 'replace' == $adjustment_type ) ) {
                                        if ( $is_anonymous ) { // note: if you put a link or other html tags in the text, be sure to use single quotes
                                            $text = "Sorry, you don't have access to this page. Please log in or contact an administrator.";
                                        } else {
                                            $text = "Sorry, this page requires additional permissions. Please contact an administrator for help.";
                                        }
                                    }

                                    break;

                                case 'my_custom_type':
                                    if ( ( 'content' == $post_part ) && ( 'replace' == $adjustment_type ) ) {
                                        if ( $is_anonymous ) {  // note: if you put a link or other html tags in the text, be sure to use single quotes
                                            $text = "Sorry, you don't have access to this custom content. Please log in or contact an administrator.";
                                        } else {
                                            $text = "Sorry, this custom content requires additional permissions. Please contact an administrator for help.";
                                        }
                                    }

                                    break;
                            }

                            return $text;
                        }

Professional publishing plugins for WordPress! Get PublishPress

  • SUBSCRIBE TO OUR NEWSLETTER
  • SEARCH THIS SITE