1

What I want is to get the output of the Twitter oEmbed system into my actual posts. IMHO the embed output itself is high-quality, semantic HTML and I'd rather have it inside the post than in the embed metadata in case their js stops working (in which case the tweet would display as a sensible blockquote).

So what I need is to hijack the oEmbed system and, upon processing it, replace the embed URL in the post with the HTML from Twitter. Clearly the solution should also be able to handle other kinds of embeds.

UPDATE: Just to be clear, I know how oEmbed works by default (i.e. the URL will be replaced with the oEmbed HTML when the 'the_content' filter is run on the post content) and that is not what I want. What I need is a way to hijack that system and, instead of only having the content replaced at display time, have the embed URL itself replaced inside the post_content in the the database with the HTML returned from the oEmbed provider.

  • 1
    Did you ever solve this? Chances are you just need to parse the post content on save and replace the links with the resulting code yourself. There should be regEx to find oEmbed URLs, then another function to force generate the response from the URL. You would only need to swap them at that point. The downside is that 3 years later in the tech world produces a completely different embed usually. So all your hard work will be obsolete at some point. – jgraup Nov 8 '16 at 12:14
1

Check out the embed API, particularly the functions wp_oembed_add_provider() and wp_embed_register_handler().

What version of WP are you running at the moment? And what happens when you place a Twitter URL on its own line in plain text? 3.4+ should handle embeds, never tried it myself.

  • I updated the question to clarify why this answer doesn't help. Twitter is already a built-in oEmbed provider so I don't need to register them. What I want is a reliable way to replace the embed URL with the embed HTML inside the post content in the database, rather than only having it replaced at load time. – jerclarke Jul 12 '13 at 15:12
  • 2
    Gotcha. Are you aware that WP caches oEmbed responses as transients, so it's not as resource-intensive as you might think? – TheDeadMedic Jul 13 '13 at 2:00
-2

This will be copyright violation and it is very not recommended to do from a legal perspective.

From a technical perspective, embeded code many times uses "external" resources like JS and CSS that might load in the context of an iframe but not in the context of your site.

So, it is both a legal and technical mine field which you probably should not even attempt to step in.

  • Copyright violation: interesting but not at all important to me. The site I was asking about is twitter, who offer the same code to copy/paste on their site so I'm not worried. And even if they didn't, copyright is triggered when WP caches the content in a transient, so saving it in the post itself doesn't change anything. – jerclarke Dec 8 '16 at 20:10
  • Re: JavaScript - also not relevant. The script loaders are in the oembed output so they would be in the post (again, just like if I had pasted it from their site). I would have to be careful about the visual editor of course and make sure the code is stable there (once again, same as if it was pasted in). In the twitter case what I want to save is their elegant block quote format, which works great even without any JavaScript. – jerclarke Dec 8 '16 at 20:12
  • 1. it is a copyright violation. 2. no the oembed will give you an iframe in all sane cases, the iframe will include css or js that if they work might interact negatively with your site – Mark Kaplun Dec 8 '16 at 21:33
  • If you're a copyright lawyer you can try to prove that it's somehow a violation to copy the oembed output from the transient into the post content, otherwise I'm not interested in your attempts to do so. – jerclarke Dec 8 '16 at 21:35
  • You are wrong about the Twitter oEmbed output and/or you consider Twitter insane, not really interested in which it is. – jerclarke Dec 8 '16 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.