• Resolved tddjaved

    (@tddjaved)


    Hi,

    I have used Elementor and the text editor widget to add content;

    The hyperlinks have added target=”_new” and i want to remove this from the serialized data in the postmeta table – how can I do this?

    I have tried running a script but it’s not fetching the posts to make the change.

    https://prnt.sc/ZkFPEk4roQZ5

    Thanks,
    Javed

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Elementor Team

    (@ricav)

    Hi Javed,

    Thank you for reaching out.

    Could you please provide us with the page URL where we can check the hyperlink and a screen recording showing the steps you took to add the hyperlink in the Text Editor widget? You can use tools such as loom.com to record your screen.

    Kind regards,

    Thread Starter tddjaved

    (@tddjaved)

    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

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.