Keep Elementor Templates Out of Search Engines
Sends visitors who open a saved Elementor template's own address back to the homepage and marks those pages noindex, so loose template URLs never show up in Google.
Opens WPIDE on
Code
add_action( 'template_redirect', function () {
if ( ! is_singular( 'elementor_library' ) || current_user_can( 'edit_posts' ) ) {
return;
}
if ( isset( $_GET['elementor-preview'] ) || isset( $_GET['preview'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
return;
}
wp_safe_redirect( home_url( '/' ), 301 );
exit;
} );
add_filter( 'wp_robots', function ( $robots ) {
if ( is_singular( 'elementor_library' ) ) {
$robots['noindex'] = true;
$robots['nofollow'] = true;
}
return $robots;
} );
Notes
Logged-in editors and Elementor previews are not redirected.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.