WordPress Tip: Custom shortcode for including CSS & HTML

If you want to include HTML and/or CSS in your blog post, try adding this to your theme’s functions.php:

function include_func($atts) {
   extract(shortcode_atts(array(
         'html' => '',
         'css' => '',
      ), $atts));
   if ($css!='') {
      global $stylenum;
      if (!isset($stylenum)) $stylenum=0;
      $thisstylename='externalStyle'.$stylenum;
      wp_register_style($thisstylename,'/'.$css);
      wp_enqueue_style($thisstylename);
      $stylenum++;
   }
   if ($html!='') {
      ob_start();
      $filename=getcwd()."/".$html;
      include($filename);
      $output=ob_get_contents();
      ob_end_clean();
      return $output;
   }
}
add_shortcode('include','include_func');

Usage in a wordpress post:

Continue reading WordPress Tip: Custom shortcode for including CSS & HTML