Return 404 response code for certain query strings in WordPress

When WordPress site owners have been victims of hacking they often suffer consequences by getting blocked by Google or getting warnings from Google about malicious URLs on their site. After cleaning the site, these problems can linger when the URLs are only query strings and not actual URLs because query strings will not trigger a 404 in WordPress. One way of fixing this is to gather all the nasty query strings and then set them up to trigger a 404. Here is a basic script that does just that.

To add query strings to the list that triggers a 404, add them in the “force404” array. In the example below the following URLs force a 404.

mywebsite.com/?some-spammy-query
mywebsite.com/?another-spammy-query

Please note that this script requires a 404 template so make sure your theme has one.



add_filter('template_redirect', 'my_404_override' );
function my_404_override() {
	$qs = $_SERVER['QUERY_STRING'];
	$force404 = Array(
		"some-spammy-query",
		"another-spammy-query"
	);
	if (in_array($qs, $force404)) {
		status_header( 404 );
		nocache_headers();
		include( get_query_template( '404' ) );
		die();
	}
}

Noteringar Juni-Juli 2016

7 juni 2016
Cyxone AB

8 juni 2016
The Marketing Group Plc
Absolicon Solar Collector AB

9 juni 2016
PiezoMotor Uppsala AB
Lauritz.com Group A/S
Bonava

10 juni 2016
Nordic Waterproofing Holding A/S
Enorama Pharma AB

13 juni 2016
Medical Prognosis Institute A/S
B3IT Management AB

14 juni 2016
Swedencare AB
Cereno Scientific AB
TF Bank AB

15 juni 2016
Redwood Pharma AB
AcadeMedia AB

16 juni 2016
GS Sweden AB

20 juni 2016
Shortcut Media AB

21 juni 2016
Alelion Batteries AB
Dignita Systems AB

27 juni 2016
Provide IT Sweden AB

29 juni 2016
VideoBur Sthlm Int AB

30 juni 2016
Crowdsoft Technology AB

5 juli 2016
Maha Energy AB

11 juli 2016
SynAct Pharma AB

14 juli 2016
Gold Town Games AB

27 juli 2016
ExpreS2ion Biotech Holding AB

Rödbetssoppa

  • Rödbetor (500g-1kg)
  • 1 gul lök
  • 2 vitlöksklyftor pressade
  • 1 boll ingefära
  • Chili 1 tsk (frukt el sambal)
  • 2 Oxbuljong
  • 1 citron
  • Gräddfil/Creme fraiche vid servering

Hacka och fräs grönsakerna. Koka ca 30 min. Mixa slät. Servera m klick Creme Fraiche.