Tag Archives: PHP

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:
[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’);[/php]

Usage in a wordpress post:

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

301 Redirect Using PHP & BASH For Static Content Migration

Here is a handy BASH Script for redirecting static content to a new location

Example: redirect foo.html bar.html

This will make foo.html redirect to bar.html and save the old foo.html as foo.html_

[bash]#!/usr/local/bin/bash
SOURCE=$1
DEST=$2
OLDSUFFIX="_"
echo "Source: $SOURCE Dest: $DEST"
if ([ -z $SOURCE ] || [ -z $DEST ]); then {
echo "usage: php_redirect [SOURCE] [DEST]";
echo "Old file will be saved as [SOURCE]$OLDSUFFIX";
}
else {
if [ ! -f $SOURCE ]; then
echo "Source: \"$SOURCE\" does not exist"
else {
mv $SOURCE $SOURCE$OLDSUFFIX
echo "<?php header(\"Location: $DEST\");" > $SOURCE;
echo "Success! $SOURCE is saved as $SOURCE$OLDSUFFIX, $SOURCE is redirected to $DEST";
}
fi
}
fi[/bash]