WordPress and buddypress programming

Display content only to visitors

Viewing 0 reply threads
  • Author
    Posts
    • #2282
      michael mc
      Keymaster
      @michael

      To set up a shortcode that displays content only to visitors, add this to your theme’s functions.php file:

      PHP
      function content_for_visitors($atts, $content = null) {
      	if ((!is_user_logged_in() && !is_null($content)) || is_feed()) {
      		return $content;
      	}
      	return '';
      }
      add_shortcode('visitors', 'content_for_visitors');

      With that code in place, you can add custom for visitors with a simple shortcode in any post or page, like so:

      [visitors]
      This content will only be displayed to visitors.
      [/visitors]
Viewing 0 reply threads
  • You must be logged in to reply to this topic.