Title: Replace all post and page content programatically
Last modified: July 4, 2019

---

# Replace all post and page content programatically

 *  Resolved [Felty](https://wordpress.org/support/users/felty/)
 * (@felty)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/replace-all-post-and-page-content-programatically/)
 * Question… I’ve been looking at the `add_action('template_redirect', 'vidyen_check_lock_cookie');`
   and other hooks for a plugin that requires the user to accept (its a bit different
   that GDPR though) but it won’t show any content or pages until they click the
   button to agree.
 * The headers and side bars should be fine but I want to replace every singe pages
   and post with the message they must agree and then click the button.
 * I’m trying to make a content locker so its not just blocked by a js script but
   rather the php simply won’t load the content so I can’t be bypassed by the client.
 * The `template_redirect` is around the area, but I still want to load the theme
   but inject right before the content loads and replace the post and page contents
   until the cookie or other if conditions has been met.
 * What add_action should I go with?
 * Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [catacaustic](https://wordpress.org/support/users/catacaustic/)
 * (@catacaustic)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/replace-all-post-and-page-content-programatically/#post-11699057)
 * The one that I’d use myself is the ‘the_content’ filter.
 * [https://codex.wordpress.org/Plugin_API/Filter_Reference/the_content](https://codex.wordpress.org/Plugin_API/Filter_Reference/the_content)
 * Somwthing like this (very much shortened)…
 *     ```
       function my_replace_content ($content) {
           if (has_clicked_button() === true) {
               $content = 'You must agree first.';
           }
   
           return $content;
       }
   
       add_filter ('the_content', 'my_replace_content', 100);
       ```
   
 *  Thread Starter [Felty](https://wordpress.org/support/users/felty/)
 * (@felty)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/replace-all-post-and-page-content-programatically/#post-11701381)
 * Awesome thanks so much!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Replace all post and page content programatically’ is closed to new replies.

## Tags

 * [add_action](https://wordpress.org/support/topic-tag/add_action/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 2 replies
 * 2 participants
 * Last reply from: [Felty](https://wordpress.org/support/users/felty/)
 * Last activity: [6 years, 11 months ago](https://wordpress.org/support/topic/replace-all-post-and-page-content-programatically/#post-11701381)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
