function custom_url_scraper($url) { // Get the HTML content of the URL $html = file_get_contents($url); // Parse the HTML content $dom = new DOMDocument(); @$dom->loadHTML($html); // Get the title $title = $dom->getElementsByTagName('title')->item(0)->textContent; // Get the featured image URL $image_url = ""; $meta_tags = $dom->getElementsByTagName('meta'); foreach ($meta_tags as $meta) { if ($meta->getAttribute('property') == 'og:image') { $image_url = $meta->getAttribute('content'); break; } } // Get the post content $content = ""; $content_div = $dom->getElementById('main'); if ($content_div) { $content = $content_div->textContent; } // Create a new post $new_post = array( 'post_title' => $title, 'post_content' => $content, 'post_status' => 'draft', 'post_author' => 1, 'post_type' => 'post' ); // Insert the post into the database $post_id = wp_insert_post($new_post); // Set the featured image if ($post_id && $image_url) { $image_id = media_sideload_image($image_url, $post_id, '', 'id'); if (!is_wp_error($image_id)) { set_post_thumbnail($post_id, $image_id); } } return $post_id; }