CyberD.org
C:\ Home » Blog » Tech » Simple Flash Embed Shortcode With WordPress

Simple Flash Embed Shortcode With WordPress

I spent a long time earlier trying to find a Flash plugin for WordPress that worked OK, until I decided to just make my own function. Piece of cake! Why didn't I try this earlier.

I used this code from CSS Tricks, checked the Shortcode API page on WordPress and combined a sample function code:

function my_shortcode_handler( $atts, $content = null ) {
    $a = shortcode_atts( array(
        'attr_1' => 'attribute 1 default',
        'attr_2' => 'attribute 2 default',
        // ...etc
    ), $atts );
}

...with the embed code:

<object type="application/x-shockwave-flash" 
  data="your-flash-file.swf" 
  width="0" height="0">
  <param name="movie" value="your-flash-file.swf" />
  <param name="quality" value="high"/>
</object>

...and here's the result!

add_shortcode( 'swf', 'shortcode_swf' );
function shortcode_swf( $atts ) {
	extract(shortcode_atts(array(
		"url" => '',
		"width" => '580',
		"height" => '400',
		"quality" => 'high',
	), $atts ));
	return '<div class="flash"><object type="application/x-shockwave-flash" data="'.$url.'" width="'.$width.'" height="'.$height.'"><param name="movie" value="'.$url.'" /></object></div>';
}

Embedding a Flash file is as simple as with any other plugin, simply use the shortcode created above like this: [swf width="580" height="160" url="http://site.ext/swf/1/file.swf" width=550 height=400]

In difference from most outdated plugins out there, this one doesn't rely on JS to work either.

You can add in extra attributes if you like, or how about adding a 'parameters' attribute through which you can add in any and all parameters directly via the shortcode? For me though, this is all I need.

Comments

Keep track of the discussion via rss? Read about comment etiquette? Or type in something below!
  1. S3C
    Friday Oct/7/2016

    cool! now we can (simply) play Flash games on blogging platforms

  2. Cyber
    Friday Oct/7/2016

    Simply put it's pretty simple now. :) I have a bunch of those left to post too. Old NG stuff. From back in the day. Before it disappeared. All I really got around to porting back then was the Music Player series... which I'm pondering if I should keep up because not all of them are probably entirely legal and since this is my own site I suppose I'm responsible for such things... it was easier when they were up on NG and it was up to them! Guess I'll see what happens...



The Comment Form

Your email address will not be published. Required fields are marked *

Your email is saved only to approve your future comments automatically (assuming you really are a human). ;) It's not visible or shared with anyone. You can read about how we handle your info here.

Question   Razz  Sad   Smile  Redface  Biggrin  Surprised  Eek   Confused   Cool  Mad   Twisted  Rolleyes   Wink  Idea  Neutral

Privacy   Copyright   Sitemap   Statistics   RSS Feed   Valid XHTML   Valid CSS   Standards

© CyberD.org 2022
Keeping the world since 2004.