Stop WordPress Content Scraping Through Feeds, the REST API and Load More

Date:

Someone copies your whole archive and never crawls a single page. A default WordPress site hands every post’s full text to any visitor who asks the right three addresses.

The short answer: WordPress content scraping rarely needs a crawler. The RSS feed carries each post’s full text and pages through the whole archive, the REST API returns up to 100 posts per request, and many themes’ “load more” buttons accept whatever page size the browser sends. On a test site with 41 posts, each of those three handed over everything in one to five anonymous requests. Set the feed to show summaries (or turn feeds off), cap the REST API’s page size and keep full text from visitors who aren’t logged in, and clamp the load-more page size on the server. Page-by-page crawling is left, and that’s a job for rate limiting.

Three doors that open WordPress content scraping

A scraper wants the text, not your design. It goes looking for addresses that return a lot of content in a predictable format, and WordPress has three of them on a default install. On a test site with 41 posts of about 380 words each, logged out, with nothing changed:

door                          requests  posts copied  with full text
feed, paged (/feed/?paged=N)  5         41            40
REST API (?per_page=100)      1         41            40
load more (per_page=1000)     1         41            41Code language: JavaScript (javascript)

The one post without “full text” in the first two rows is WordPress’s own short “Hello world” post. Everything else came out whole.

Your archive doesn’t need to be crawled. It’s sitting behind three addresses that answer anyone.

Door 1: the feed sends the full text

WordPress’s feed at /feed/ shows the latest ten posts, and by default each item carries the post’s complete text. It also takes a page number: /feed/?paged=2 returns the next ten, and so on until the archive runs out. On the test site, five requests returned all 41 posts.

The quickest fix is a setting. In Settings > Reading, set For each post in a feed, include to Excerpt (the Reading screen documents it). After that, the same five requests returned all 41 titles and summaries, and none of the full text. Feed readers still work, and they link back to your site for the rest.

If nobody reads your site by feed, you can turn feeds off. This returns an empty 404 for every feed, including the category, comment and Atom versions, and removes the feed links from your pages’ head:

// No feeds at all: every feed address answers 404.
add_action( 'template_redirect', function () {
    if ( is_feed() ) {
        status_header( 404 );
        nocache_headers();
        exit;
    }
}, 1 );
remove_action( 'wp_head', 'feed_links', 2 );
remove_action( 'wp_head', 'feed_links_extra', 3 );
Code language: PHP (php)

On the test site, the post feed, the Atom feed, a category feed and a post’s comment feed all answered 404 with an empty body, and the home page was unchanged. Check first whether anything relies on your feed (an email newsletter tool, a podcast directory, a partner site) before switching it off.

Door 2: the REST API returns 100 posts at a time

The REST API is how the block editor and many plugins talk to WordPress, and its post list is public. /wp-json/wp/v2/posts?per_page=100 returns up to 100 posts with their full content, and the X-WP-Total header tells the scraper how many there are in all. On the test site, one request returned all 41.

Two filters close most of it. The first caps the page size, so a request for more than 20 is refused. The second keeps the full text out of the answer for visitors who aren’t logged in, while titles, links and excerpts stay:

// 1. REST API: at most 20 posts per request.
add_filter( 'rest_post_collection_params', function ( $params ) {
    $params['per_page']['maximum'] = 20;
    return $params;
} );

// 2. REST API: no full text for visitors who aren't logged in.
add_filter( 'rest_prepare_post', function ( $response ) {
    if ( ! is_user_logged_in() ) {
        $data = $response->get_data();
        if ( isset( $data['content'] ) ) {
            $data['content'] = array( 'rendered' => '', 'protected' => false );
        }
        $response->set_data( $data );
    }
    return $response;
} );
Code language: PHP (php)

After both, per_page=100 answered 400 rest_invalid_param, and a page of 20 came back with an empty content field and the excerpt intact. A logged-in editor still got the full text, so the block editor kept working. The filter names follow the post type: rest_page_collection_params and rest_prepare_page do the same for pages, as the reference for rest_{$this->post_type}_collection_params and rest_prepare_{$this->post_type} explains.

A cap alone only slows a scraper down: 41 posts at 20 per request is three requests. Withholding the content is what actually closes this door. Leave it out only if something outside the site reads your posts through the API, such as a mobile app or a separate front end, and then give that client a login.

Door 3: the load-more button takes any page size

Many themes and post-grid plugins load the next batch of posts through admin-ajax.php when a visitor clicks “Load more” or scrolls. The browser sends the batch size, typically 6 or 12, and the handler often uses whatever number it receives. Sent by hand with 1,000, the test site’s handler returned all 41 posts with their full text in one request.

The fix belongs in the handler: clamp the number it reads before it runs the query.

// In the load-more handler, before the query: never trust the page size the browser sends.
$per_page = isset( $_POST['per_page'] ) ? absint( $_POST['per_page'] ) : 12;
$per_page = min( max( $per_page, 1 ), 12 );
Code language: PHP (php)

With the clamp, the same request returned 12 posts. If the handler is in a theme or plugin you didn’t write, find its AJAX action in the browser’s Network panel (filter by admin-ajax), send it a large number, and count what comes back. If it obeys, ask the developer for a fix, or filter the query it runs: many expose a filter for their query arguments.

Every number a visitor’s browser sends is a number the visitor can change.

What this doesn’t stop

None of this stops someone fetching your pages one by one and copying the text out of the HTML. Your sitemap lists every URL, and a public page has to show its content. The aim is narrower: no address that returns your whole archive in a few requests. What’s left takes one request per page, which is slow, visible in your logs, and what rate limiting is built to catch. Where to block or slow bots so that a page cache doesn’t wave them through is in where to block bots, and what crawlers cost you in bandwidth is in CDN bandwidth spent on bots.

After any of these changes, purge your page cache, then repeat the requests logged out: the feed, the REST API with per_page=100, and the load-more action with a large number.

The short version

  • The feed pages through every post with full text by default: set it to excerpts, or turn feeds off if nothing relies on them.
  • The REST API returns up to 100 posts per request: cap the page size, and keep full text from visitors who aren’t logged in.
  • A load-more handler often uses whatever page size it’s sent: clamp it on the server.
  • Page-by-page crawling remains, and that’s for rate limiting.
  • Test logged out after purging the cache, with the same requests a scraper would send.

Frequently Asked Questions

Does switching the feed to excerpts hurt SEO?

Search engines index your pages, not your feed, so the full text stays on the post where they find it. Excerpts in the feed send readers to the post itself.

Will blocking the REST API break my site?

Turning the whole REST API off for logged-out visitors can break plugins that use it from the front end, such as contact forms and search widgets. The two filters here don’t block anything: they cap the page size and empty one field for logged-out visitors, so every route keeps answering.

Can a plugin do this instead?

Security plugins often have a switch that disables the REST API or feeds for logged-out visitors. Test what it turns off: a full block of the REST API stops contact forms that submit through it. None of them can fix a theme’s load-more handler. That fix has to go in the handler itself.

Share post:

Subscribe

Popular

More like this
Related

Contact Form 7 Scripts on Every Page? Load Them Only Where a Form Is Shown

Your site has one contact form, yet every page downloads Contact Form 7's stylesheet, two scripts and a block of settings. The plugin has its own switch for that. The catch is the form that isn't in the page content.

Test WordPress SMTP Without Sending a Single Real Email

You changed the SMTP settings, or copied a live site to staging, and you need to know whether mail works. Every test you can think of either lands in a real inbox or, on a copy of a live site, could reach a real customer.

Contact Form 7 Emails Going to Spam? Send Them Through Your Own Mailbox With FluentSMTP

The form said "Thank you for your message. It has been sent." It had been. Straight into the spam folder.

Git Hook Not Running? Five Reasons It Does Nothing, and How to Tell Which

You added a pre-commit hook to block a mistake. You make the mistake on purpose to test it, and the commit goes through. No error, no output. Is the hook running at all?