You can try to use the template_redirect
hook to check your conditions and then set the wp_query->is_404
variable, like below:
function wpse202198_set_404(){
global $post;
global $wp_query;
if( $post->ID == PAGE_ID_OF_PROTECTED_PAGE ){
$wp_query->is_404 = true;
return;
}
}
add_action( 'template_redirect', 'wpse202198_set_404' );
Related Posts:
- How to use nonce with front end submission form?
- Mega Menu Walker
- How to add a class to the attachment images
- How to export/import theme customizer settings?
- Why would a GET variable one one page of a site cause a 404 error when a GET variable works on another page of a site?
- Why can I not use setup_postdata($post) in the sidebar?
- Drop down+sort blog posts date added/most popular
- Activate different theme for temporary preview
- Get WooCommerce shipping methods programmatically
- Add a custom text field to WooCommerce admin product data “Variations”
- How do I output a database option that is an array into a get_posts array?
- Passing jQuery value using Ajax to a page template
- Change logo based on incoming domain
- Why can’t I use “%s” format value in the WordPress function checked?
- Creating login session via CURL
- Help with some php math in WordPress
- max_input_vars: how many am I using?
- WordPress vs. Custom PHP [closed]
- Trouble With Conditional Logic in PHP
- Multiple WordPress Menus that will only display all pages
- How to make drop down post title
- how to delete 30 day old data using PHP [closed]
- Remove meta description on certain pages
- Image media upload metabox
- Is there CSS to expand the gallery limit on Index Pages?
- Hide categories that are not used in the post type
- esc_html_e() is not translating string in wordpress [closed]
- WordPress, AJAX and pre_get_posts using conditional tags
- Limit 1 global comment per minute
- How can I add an area/option for a custom page description?
- Is there a way to conditionally check whether a WordPress post title is empty?
- Echo a function inside a function
- Download full html page with CSV export plugin
- Advanced Custom Fields – display label and value only if value entered
- Use WordPress function in php file
- Is it bad to add html to a widget by closing and reopening the php tags?
- How to parse multiple links from one variable?
- how to disabled a button when press three times
- $wpdb returns duplicate posts
- How Can I Edit the Registration Code?
- My jQuery Ajax form submit is still refreshing page?
- load more button in plugin
- Display attribute on shop page after the title
- Cant connect to database with php 7.3
- Illegal string offset error in wordpress theme options textarea
- WordPress WP_Query without query GET parameters
- How to clone all WordPress Rest API end points
- Controlling image output size ACF repeater [closed]
- Initial offset of number of posts in home page on the posts page
- Run JS Code on userlog out
- Using Custom Value Options in PHP
- How to prevent a function from running based on host (ie web vs local)?
- Additional file upload in Gutenberg page options/featured image
- Delete images from media library when user deletes an image from ACF Gallery
- Array data not saving to specified sections. How to make seting independantly?
- How to get woocommerce orders with get_posts method in a shortcode
- Add css class to string
- Replace custom SVG icons in Twenty Twenty-One
- Integrate otp in my custom singup form
- Change category thumbnail size
- Dropdown Category form. Only show Sub-Categories
- Display all categories including sub categories under a list ul
- WP Hook Before a post is created
- Unable to retrieve get_author_posts_url
- Polylang and template files
- Add custom ID attribute to all woocommerce products on archive pages
- problem in using wpdb->prepare and a string placeholder
- Custom content using in_category
- Efficient way of querying for a “fallback” post?
- Shortcode in a $output statement
- Need help with PHP functions
- WP Redirect with user nickname/username
- When using shortcode, content stops generating after the_content
- Archive page if else not working for post_excerpt and post_content
- How do you detect if a specific word is at the end of a the_title()
- WordPress styling recent post
- add bootstrap modal after login in wordpress
- featured post as div background
- Combining fancybox with multiple thumbnail plugin
- How to display thumbnail if post is assigned one otherwise not
- syntax error unexpected ‘}’ at 364 line
- get_post_meta no longer working
- Highlight posts currently being edited on multiple editor site?
- How to check “From Email” via WordPress before an email is sent
- WordPress Plugin Receive a Link
- How to use plugins_url() inside PHP stylesheet file [duplicate]
- Php echo into tag
- Using Excel formula in PHP. Use ^ symbol [closed]
- PHP warning Invalid argument supplied for foreach() on custom page template
- Assign new post author IF another user in custom field on post transition
- Create and publish a new post every Monday, listing the post titles and links to the posts published during the previous week
- Remove Unused Menu Locations
- How to cut a section of a URL from a string with a regular expression?
- Too few arguments at registering new templates in my plugin
- inner-wrap div pushing custom table far down on page
- Remove Woocommerce product from cart with ajax/fetch
- Custom nav with bootstrap dropdown
- Limit a search box by CPT + taxonomies, in only one page
- How to edit a widget code?
- Hide ‘Downloadable’ and ‘Virtual’ checkbox options from Woocommerce Variations?