Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
I am trying to set up a shortcode within kfunctions.php so that a video can be embedded into a post. The problem I am facing is that it uses javasript for the embed. Is there a way to make this embed link work as a shortcode?

Code: Select all
<script type='text/javascript' src='http://KMIR.images.worldnow.com/interface/js/WNVideo.js?rnd=851976;hostDomain=www.kmir.com;playerWidth=645;playerHeight=360;isShowIcon=true;clipId=11724499;flvUri=;partnerclipid=;adTag=Station%25201;advertisingZone=;enableAds=true;landingPage=;islandingPageoverride=false;playerType=STANDARD_EMBEDDEDscript;controlsType=overlay'></script><a href="http://www.kmir.com" title="KMIR News | Palm Springs, California">KMIR News | Palm Springs, California</a>


Functions code:
Code: Select all
<?php
   $FUNCS->register_shortcode( 'embed', 'embed_handler' );
   function embed_handler( $params, $content=null ){
      global $FUNCS;

      extract( $FUNCS->get_named_vars(array(
         'code' => '',
      ), $params) );

       return $code;
   }
The problem here is the word 'script' which gets sanitized, so you can't use the all-purpose shortcode for this. The only way I've found to include this type of code in a richtext area is to create a one-off shortcode specifically for that purpose. This means, though, that the developer has to create the shortcode, it can't just be embedded by the client. You also have to watch the quotation marks. Something with single quotes inside double quotes won't work because it will close the shortcode prematurely.

Try this and see if it works.
Code: Select all
// One-off shortcode
   // Usage: [KMIRNewsClip]
   $FUNCS->register_shortcode( 'KMIRNewsClip', 'KMIRNewsClip_handler' );
   function KMIRNewsClip_handler( $params, $content=null ){
      return '<script type="text/javascript" src="http://KMIR.images.worldnow.com/interface/js/WNVideo.js?rnd=851976;hostDomain=www.kmir.com;playerWidth=645;playerHeight=360;isShowIcon=true;clipId=11724499;flvUri=;partnerclipid=;adTag=Station%25201;advertisingZone=;enableAds=true;landingPage=;islandingPageoverride=false;playerType=STANDARD_EMBEDDEDscript;controlsType=overlay"></script><a href="http://www.kmir.com" title="KMIR News | Palm Springs, California">KMIR News | Palm Springs, California</a>';
   }
Thanks tim! That is exactly what I needed.
3 posts Page 1 of 1