- return preg_replace_callback( '|^\s*(https?://[^\s"]+)\s*$|im', array( $this, 'autoembed_callback' ), $content );
+ // Strip newlines from all elements.
+ $content = wp_replace_in_html_tags( $content, array( "\n" => " " ) );
+
+ // Find URLs that are on their own line.
+ return preg_replace_callback( '|^(\s*)(https?://[^\s"]+)(\s*)$|im', array( $this, 'autoembed_callback' ), $content );