Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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