79463668

Date: 2025-02-24 13:25:40
Score: 1
Natty:
Report link

Method 1

Add the following code to your theme's functions.php file...

add_action('template_redirect', function() {
$urls_to_404 = [
    '/example-page/',    // Replace Url
    '/example-page 2/',
];

$current_url = $_SERVER['REQUEST_URI'];

foreach ($urls_to_404 as $url) {
    if (trailingslashit($current_url) === trailingslashit($url)) {
        global $wp_query;
        $wp_query->set_404();
        status_header(404);
        nocache_headers();
        include(get_query_template('404'));
        exit;
    }
} });

Method 2

Using a Redirect Plugin Install "Redirection" plugin. Go to Tools > Redirection. Add a new redirect:

Source URL: /example-page/

Target URL: 404 (select "Do nothing" and check "404 Not Found").

Plugin Url https://wordpress.org/plugins/redirection/ enter image description here

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Usama Rasool