Hi,
I have managed to resolve this with a custom PHP script, in the posts meta table, Elementor serializes the content to JSON and I needed to remove the hyperlinks attributes from there.
Here is a copy of the script;
<?php
// Include WordPress to access $wpdb
require_once( 'wp-load.php' );
global $wpdb;
// Query the wp_postmeta table for posts with target="_new" or rel="noopener" in _elementor_data
$query = "
SELECT post_id, meta_value
FROM wpc5_postmeta
WHERE meta_key = '_elementor_data'
AND (meta_value LIKE '%target=%' OR meta_value LIKE '%rel=%')
LIMIT 500;
";
$posts = $wpdb->get_results( $query );
// Check if posts are returned
if ( empty( $posts ) ) {
echo "No matching posts found in wpc5_postmeta with '_elementor_data'.<br>";
exit;
}
echo "Found " . count( $posts ) . " posts to update.<br>";
// Loop through each post to process and update
foreach ( $posts as $post ) {
echo "<br>Processing post ID: " . $post->post_id . "<br>";
// Output the raw meta_value to see the format
echo "<strong>Raw meta_value:</strong><br>";
var_dump($post->meta_value);
echo "<br>";
// Decode the JSON data
$decoded_content = json_decode( $post->meta_value, true );
if ( json_last_error() === JSON_ERROR_NONE ) {
// Process the decoded content (if it's valid JSON)
array_walk_recursive( $decoded_content, function( &$value ) {
if ( is_string( $value ) ) {
// Replace target and rel attributes
$value = str_replace( 'target="_new"', '', $value );
$value = str_replace( 'rel="noopener"', '', $value );
}
});
// Re-encode the content as JSON
$updated_meta_value = json_encode( $decoded_content );
// Update the postmeta table with the new cleaned value
$wpdb->update(
'wpc5_postmeta',
array( 'meta_value' => $updated_meta_value ),
array( 'post_id' => $post->post_id, 'meta_key' => '_elementor_data' )
);
echo "Updated post ID: " . $post->post_id . "<br>";
} else {
echo "The content for post ID " . $post->post_id . " is not valid JSON.<br>";
}
}
echo "Processing completed successfully!";
I then had to regenerate the CSS and library, cleared cache, checked the content and it’s removed those hyperlink attributes.
So I don’t think I need to share a Loom recording for this.
I’ll mark this as resolved.
Thanks
Javed