If exist the page parameter in the blog post, I have to redirect to the 404 page instead of current post URL. I tried to check the current page type (is singular) and try to get page parameter in the function.php, but I couldn't. It's doesn't work together. I need to implement it only for blog post. If possible .htaccess redirect also fine
I tried with this code but it doesn't work. But it's working without the is_single function. When I used is_single functions, the page parameter not returning.
Example Url: www.example.com/this-is-my-first-post?page=2 www.example.com/p=22?page=2
Thank you for your help. It's not working
add_action('send_headers', 'post_page_param_404_redirect');
function post_page_param_404_redirect() {
global $wp_query;
if (is_single() && isset($_GET['page'])) {
$wp_query->set_404();
status_header(404);
get_template_part(404);
exit();
}
}
When I don't use the is_single function , It's working for all page, but I need it only for the blog post
add_action('send_headers', 'post_page_param_404_redirect');
function post_page_param_404_redirect() {
global $wp_query;
if (isset($_GET['page'])) {
$wp_query->set_404();
status_header(404);
get_template_part(404);
exit();
}
}
send_headers
is executed too early.pre_get_posts
is the first hook that conditional tags can be used. Related question