WordPress Code Snippets

A fresh mix of code snippets and tutorials

Break Out of Frames for WordPress

111

Quick JavaScript snippet to prevent scrapers and turds from framing, defaming, and/or stealing your precious content..

When included in your WordPress theme’s functions.php file, this PHP snippet helps to break out of frames, so your pages are served only from the original domain, not some douchebag’s Google adsense site.

// Break Out of Frames for WordPress
function break_out_of_frames() {
	if (!is_preview()) {
		echo "\n<script type=\"text/javascript\">";
		echo "\n<!--";
		echo "\nif (parent.frames.length > 0) { parent.location.href = location.href; }";
		echo "\n-->";
		echo "\n</script>\n\n";
	}
}
add_action('wp_head', 'break_out_of_frames');

Source: George Notaras (404 link removed 2015/11/05)

Learn more

WordPress Themes In Depth


Show Support

Like our new Facebook Page to show support!