Search code examples
wordpressembedoembedwpallimport

Process embed links during wordpress import


I am using the WP All Import plugin to import content into a new wordpress installation. Everything is working well except any links that would usually show the converted embed content on the front end are showing as a link initially. I have to manually goto the post, click on the "Text" tab of the editor, then click the "Visual" tab on the editor, and then the links are processed.

Here is an example of the content being imported...

<p>Below this text should be a tweet embed.</p>

https://twitter.com/someecards/status/1040642553257906180

<p>Above this text should be a tweet embed.</p>

I am familiar with the PHP function that this import plugin lets me use, but I cannot find a filter or anything that does what I need.


Solution

  • Are you sure the formatting is correct? oEmbeds like those for Twitter links don't process the link until they're rendered on a page. I suspect that when you edit the content in the WYSIWYG editor, it reformats the content to put the twitter link on a line all by itself (which is necessary for an oembed to function.

    For example, this will not work:

    <p>Below this text should be a tweet embed.</p>
    https://twitter.com/someecards/status/1040642553257906180
    <p>Above this text should be a tweet embed.</p>
    

    But this will work:

    <p>Below this text should be a tweet embed.</p>
    
    https://twitter.com/someecards/status/1040642553257906180
    
    <p>Above this text should be a tweet embed.</p>
    

    If lack of extra newlines is the problem, you could (a) edit the incoming markup, or (b) write a processing function in WP All Import to turn every newline into double new-lines. You could also write a more complex regular expression to find oEmbed URLs and wrap [embed][/embed] tags around them.

    For more info on how oEmbeds work in WP, check out the official documentation.