WordPress.org

Forums

[resolved] Creating an RSS-Feed-only WordPress Site (2 posts)

  1. raamdev
    Member
    Posted 2 years ago #

    I'm working on a project where I'll be posting content to a WordPress site via email and then accessing that posted content via RSS. However, I don't want the content to be publicly accessible on the front-end of WordPress (i.e., web crawlers, web browsers going directly to the post URLs, etc.); the only way of viewing the post content should be via RSS.

    I'm not sure how I should go about this. Should I edit all of the template files in my theme and just remove anything that outputs the post content and title? Or is there a more simple way of doing this via hooks, e.g., using the is_feed() function to check if a feed is loading the post and then return "" if it's not a feed?

    Any examples would be greatly appreciated. Thank you.

  2. raamdev
    Member
    Posted 2 years ago #

    Just a quick update here for anyone else who might find this thread trying to do something similar.

    You can simply hide the content of all your posts, except for in RSS Feeds, by placing the following in your theme's functions.php file:

    add_filter( 'the_content', 'exclude_non_feed', 20 );
    function exclude_non_feed( $content ) {
        if ( !is_feed() ) { $content = "<strong>Sorry, this content is only available through a special RSS feed.</strong>"; }
        return $content;
    }

    For my scenario, I wanted to hide basically the entire public-facing site, so I did that by simply adding the following to the top of my theme's header.php file:

    <?php if ( !is_feed() ) { exit; } ?>

    It's not optimal, but it does what I need. If anyone can recommend a cleaner way of doing this, I'm all ears! :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags