I would like to offer an embed code on my WP blog allowing users to re-publish recent posts on their websites using HTML/ Javascript code snippet that they can copy from my WP site and paste into their non-WP site.
Can you guys help?
I would like to offer an embed code on my WP blog allowing users to re-publish recent posts on their websites using HTML/ Javascript code snippet that they can copy from my WP site and paste into their non-WP site.
Can you guys help?
You must be logged in to post a comment.
You basically need to create an area outside of your current theme in which to create some content that you can stick into an iframe.
You just give your user something like this:
And they have your posts on their site!
Step one is going to be creating a URL end point for your iframe. First you need to add a rewrite rule for the iframe, then filter the query variable to make sure WordPress recognized your new iframe query var and doesn’t strip it out.
Next up, hook into template_redirect and “catch” whenever the iframe query variable is present. If it is, you can do whatever you want. Eg. get a list of posts and display them.
All that’s left is to create some place for your users to get the iframe code. You could use a shortcode to do that, or just create a function (like the one below) to stick into your theme some place.
Here’s all that as a plugin.
I understand that you would like to present your users a JS file that they can embed in their websites to get the latest posts from your WP blog. I’d try a RSS parser 🙂
Check this out: https://stackoverflow.com/questions/226663/parse-rss-with-jquery
Quoting an answer from the linked question, the easiest way to do it with jQuery is, https://stackoverflow.com/a/7067582/807101
You simply have to take the third-party code, and wrap it inside a WordPress Widget, using the Widgets API.
Regarding the Twitter Widgets you mentioned specifically, I’ve already gone to the trouble of wrapping the Twitter code in a WordPress Widget and released it as a Plugin, so perhaps my Plugin will serve as a useful guide for using this method for other third-party scripts.
… this functionality already exists by default.
Any WordPress site can publish an external RSS feed in a widget on their site. So long as you are producing an RSS feed of your content, other WP sites can re-publish that content through a widget.
If you want to write a custom plugin to do this (i.e. create a single, installable system that doesn’t require end users to know or understand RSS), it’s actually pretty easy.
I actually publish a plugin that allows WP site owners to re-publish content from a WordPress site in their sidebar. It’s a specific site, and I only publish the results of a specific search query.
Here’s roughly what it does:
Widget Code:
The advantage here is that
fetch_feed()
will cache the feed with a transient, so I’m not hitting the remote site on every page load. It’s fast, efficient, and pretty easy to do. The plugin I linked to above pulls the latest post from a site that offers daily spiritual meditations, and I republish the latest meditation on my own site.You can see it in action on the sidebar of one of my blogs, Grounded Christianity.