Skip to content

Instantly share code, notes, and snippets.

@s-hiroshi
Created July 4, 2012 04:03
Show Gist options
  • Save s-hiroshi/3045199 to your computer and use it in GitHub Desktop.
Save s-hiroshi/3045199 to your computer and use it in GitHub Desktop.
WordPress > shortcode > pagetop
<?php
/**
* 「このページの上へ」をマークアップするショートコード。
* @attribute classname div要素のクラス名 省略 pagetop
* @attribute target アンカー名 省略 wrapper
* @attribute text リンクの文字列 このページの上へ。
* 属性がない場合は下記のHTMLコードを返す。
* <div class="pagetop"><a href="#wrapper">このページの上へ</a></div>
* 使い方[pagetop]
*/
function pagetop_func($atts) {
extract(shortcode_atts(array(
'classname' => 'pagetop',
'target' => 'wrapper',
'text' => 'このページの上へ'
), $atts));
$markup = '<div class="' . $classname . '"><a href="#' . $target . '">' . $text . '</a></div>';
return $markup;
}
add_shortcode('pagetop', 'pagetop_func');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment