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/