Created
June 29, 2012 07:30
-
-
Save s-hiroshi/3016477 to your computer and use it in GitHub Desktop.
wordPress > shortcode > heading
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* h1-h6に属性を指定してマークアップする | |
* @attribute id id名 | |
* @attribute class クラス名 | |
* 属性がない場合は下記のHTMLコードを返す | |
* <img src="%TEMPLATE_DIRECTORY%/screenshot.png" alt="*" /> | |
* %TEMPLATE_DIRECTORY%はbloginfo('stylesheet_directory') | |
* 使い方[h1 id="foo" class="bar"]Example[/h1] | |
*/ | |
// h1 | |
function h1_func($atts, $content = null) { | |
extract(shortcode_atts(array( | |
'id' => '', | |
'class' => '', | |
), $atts)); | |
$html = '<h1'; | |
if ($id) { | |
$html .= ' id="' . $id . '"'; | |
} | |
if ($class) { | |
$html .= ' class="' . $class . '"'; | |
} | |
$html .= '>' . $content . '</h1>'; | |
return $html; | |
} | |
add_shortcode('h1', 'h1_func'); | |
// h2 | |
function h2_func($atts, $content = null) { | |
extract(shortcode_atts(array( | |
'id' => '', | |
'class' => '', | |
), $atts)); | |
$html = '<h2'; | |
if ($id) { | |
$html .= ' id="' . $id . '"'; | |
} | |
if ($class) { | |
$html .= ' class="' . $class . '"'; | |
} | |
$html .= '>' . $content . '</h2>'; | |
return $html; | |
} | |
add_shortcode('h2', 'h2_func'); | |
// h3 | |
function h3_func($atts, $content = null) { | |
extract(shortcode_atts(array( | |
'id' => '', | |
'class' => '', | |
), $atts)); | |
$html = '<h3'; | |
if ($id) { | |
$html .= ' id="' . $id . '"'; | |
} | |
if ($class) { | |
$html .= ' class="' . $class . '"'; | |
} | |
$html .= '>' . $content . '</h3>'; | |
return $html; | |
} | |
add_shortcode('h3', 'h3_func'); | |
// h4 | |
function h4_func($atts, $content = null) { | |
extract(shortcode_atts(array( | |
'id' => '', | |
'class' => '', | |
), $atts)); | |
$html = '<h4'; | |
if ($id) { | |
$html .= ' id="' . $id . '"'; | |
} | |
if ($class) { | |
$html .= ' class="' . $class . '"'; | |
} | |
$html .= '>' . $content . '</h4>'; | |
return $html; | |
} | |
add_shortcode('h4', 'h4_func'); | |
// h5 | |
function h5_func($atts, $content = null) { | |
extract(shortcode_atts(array( | |
'id' => '', | |
'class' => '', | |
), $atts)); | |
$html = '<h5'; | |
if ($id) { | |
$html .= ' id="' . $id . '"'; | |
} | |
if ($class) { | |
$html .= ' class="' . $class . '"'; | |
} | |
$html .= '>' . $content . '</h5>'; | |
return $html; | |
} | |
add_shortcode('h5', 'h5_func'); | |
// h6 | |
function h6_func($atts, $content = null) { | |
extract(shortcode_atts(array( | |
'id' => '', | |
'class' => '', | |
), $atts)); | |
$html = '<h6'; | |
if ($id) { | |
$html .= ' id="' . $id . '"'; | |
} | |
if ($class) { | |
$html .= ' class="' . $class . '"'; | |
} | |
$html .= '>' . $content . '</h6>'; | |
return $html; | |
} | |
add_shortcode('h6', 'h6_func'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment