I often embed videos on my Couch generated pages. They can come from YouTube, or sometimes they're flash movies served by other sites. Other times I serve my own HTML5 video using the <video> tag. But they all have one thing in common. Each has a snippet of code you use to embed the movie on your site.
So I created an all-purpose "embed code" shortcode to allow me to easily include these snippets in richtext areas of pages.
The Couch documentation (http://www.couchcms.com/docs/miscellane ... codes.html) includes a collection of shortcode examples for many different uses, including embedding youtube videos, iframes, Google maps, and other bits of specialized code. I do all these things on my sites, but not often enough to remember how to use the specific shortcode each time.
With this all-purpose shortcode, I can add nearly any snippet of code to a page: embedded videos, iframes, HTML5 tags… just about anything. And do it with a single shortcode. Usage is simple:
There are some limitations:
1. Couch scrubs the word "script" for security purposes. For instance a flash movie with the parameter "allowscriptaccess" will break.
2. No new lines. Put everything on a single line.
3. Quotation marks. Be careful of your quotation mark types. You can accidentally close the shortcode prematurely.
Where I can't work around these issues, I create a one-off shortcode for that code with its own unique name.
These two together - the all-purpose embed shortcode and one-off shortcodes - allow me to easily add any bit of code I need into a Couch-based page. There's nothing fancy about it, but it's very handy if you hadn't already thought of it yourself.
EDIT: I updated this shortcode to pass the embed code through Couch's 'embed' function. D'uh...
Maybe not a big deal for clients, but on my own sites, I can now add couch tags for things like internal links, or even embed php with the cms:php tag.
So I created an all-purpose "embed code" shortcode to allow me to easily include these snippets in richtext areas of pages.
The Couch documentation (http://www.couchcms.com/docs/miscellane ... codes.html) includes a collection of shortcode examples for many different uses, including embedding youtube videos, iframes, Google maps, and other bits of specialized code. I do all these things on my sites, but not often enough to remember how to use the specific shortcode each time.
With this all-purpose shortcode, I can add nearly any snippet of code to a page: embedded videos, iframes, HTML5 tags… just about anything. And do it with a single shortcode. Usage is simple:
- Code: Select all
[embed code='<p>Any snippet of code goes here.</p>']
There are some limitations:
1. Couch scrubs the word "script" for security purposes. For instance a flash movie with the parameter "allowscriptaccess" will break.
2. No new lines. Put everything on a single line.
3. Quotation marks. Be careful of your quotation mark types. You can accidentally close the shortcode prematurely.
Where I can't work around these issues, I create a one-off shortcode for that code with its own unique name.
These two together - the all-purpose embed shortcode and one-off shortcodes - allow me to easily add any bit of code I need into a Couch-based page. There's nothing fancy about it, but it's very handy if you hadn't already thought of it yourself.
- Code: Select all
// All-Purpose Embed Shortcode
// Embed any code (almost).
// Careful of your quotation mark types.
// Won't accept the word "script." No new lines. PHP code won't work.
// Usage: [embed code='<p>Any code goes here.</p>']
$FUNCS->register_shortcode( 'embed', 'embed_handler' );
function embed_handler( $params, $content=null ){
global $FUNCS;
extract( $FUNCS->get_named_vars(array(
'code' => '',
), $params) );
// Pass on the code to Couch for execution using the 'embed' function
return $FUNCS->embed( $code, $is_code=1 );
}
EDIT: I updated this shortcode to pass the embed code through Couch's 'embed' function. D'uh...
Maybe not a big deal for clients, but on my own sites, I can now add couch tags for things like internal links, or even embed php with the cms:php tag.