Skip to content

Instantly share code, notes, and snippets.

@s-hiroshi
Created June 29, 2012 06:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s-hiroshi/3016372 to your computer and use it in GitHub Desktop.
Save s-hiroshi/3016372 to your computer and use it in GitHub Desktop.
WordPress > shortcode > br
<?php
/**
* 属性numに指定した数の改行をマークアップ。
* @attribute num 改行の数
* 使い方[bar num="3"] 3回改行
*/
function br_func($atts) {
extract(shortcode_atts(array(
'num' => '1'
), $atts));
$num = intval($num);
$html = '';
if ($num == 1) {
$html = "<br />";
} else if ($num > 1) {
for ($i=0; $i<$num; $i++) {
$html .= "<br />";
}
}
return $html;
}
add_shortcode('br', 'br_func');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment