Remote Content Shortcode
Note: This plugin is now part of the WordPress Plugin Repository as Remote Content Shortcode.
The Remote Content Shortcode plugin will enable a shortcode to display remote content embedded into a post or page. In fact, it is being used to embed the code below from my SVN server. To use it, just place the code in your page where you want to remote content to be placed.
[remote_content url="http://www.example.com"/]
By default this will just fetch the content and drop it straight into the page, which isn’t always ideal (like when you are using a code formatter like I am). Because of this, there are a few more parameters you can pass to Remote Content Shortcode:
url
– the url that you want to request.method=[ GET | POST ]
– set the request type, defaults toGET
.timeout=[ 0-9... ]
– set the request timeout in seconds, defaults to10
seconds.userpwd=[ username:password | post_meta | site_option | constant ]
– the username and password to send forBASIC
authentication. It is recommended to not set the username and password directly in the tag, as it will be visible on your site if this plugin is disabled, and instead use one of the other options. By order of priority, if the value matches a postmeta_key
themeta_value
is used, if it matches asite_option
theoption_value
is used, and if it matches a constant the constant value is used, otherwise the data is passed as is. The format isusername:password
.htmlentities=[ false | true ]
– if you want to HTML encode the content for display set totrue
, defaults tofalse
.strip_tags=[ false | true ]
– remove all tags from the remote content (after CSS selection).decode_atts=[ false | true ]
– the SyntaxHighlighter plugin will HTML encode your shortcode attributes, soattr="blah"
becomesattr="blah"
. This fixes it to the intended value when set totrue
, defaults tofalse
.selector=[ CSS Selectors... ]
– the CSS selector or comma separated list or selectors for the content you would like to display, for examplediv.main-content
ordiv.this-class #this-id
, defaults to the entire document.remove=[ CSS Selectors... ]
– the CSS selector or comma separated list or selectors for the content that you would like to remove from the content, for exampleh2.this-class
ordiv#this-id
, defaults to no replacement.find=[ regex ]
– use a PHP regular expression to find content and replace it based on thereplace
attribute, for example~http://([^\.]*?)\.example\.com~
, defaults to disabled.replace=[ regex ]
– the replacement text to use with the results of thefind
regular expression, for examplehttps://\\1.new-domain.com
, defaults to empty string replacement.cache=[
true
| false ]
– set tofalse
to prevent the contents from being cached in the WP-Cache/WordPress transients, defaults totrue
for performance.cache_ttl=[ 0-9... 3600 ]
– the cache expiration in seconds or0
for as long as possible, defaults to3600
seconds.
[remote_content url="http://www.example.com" method="POST"] { json: { example: request } } [/remote_content]
This source files for Remote Content Shortcode are always up to date based on the trunk of the WordPress Plugin SVN repository.
remote-content-shortcode.php
<html> <head><title>403 Forbidden</title></head> <body> <center><h1>403 Forbidden</h1></center> <hr><center>nginx</center> </body> </html>
Great plugin! Is ti possibile to get HTML which is loaded by Javascript as well?
The content is loaded by curl and parsed by PHP so unfortunately there is no Javascript engine to load any additional HTML.
This is really sweet, man. I like the code formatting. Great plugin and great post.