3.01 functions.php
<?php
add_filter("contextual_help","my_help");
function my_help($help){
return $help."my help";
}
?>
すべてのページのoverviewタブに表示されます
テーマオプションページなど特定のページで表示する場合は
WordPress 3.91 functions.php
$hook_suffix= add_theme_page(... );
上記のように、add_theme_pageの返り値を取得して、
add_action( 'load-' . $hook_suffix, array( $this, 'enough_settings_page_contextual_help' ), 20 );
テーマオプションページだけで動作するようにフックします
ヘルプページの例は、以下のようになります
WordPress Theme Enoughで実際の動作を確認できます
function enough_settings_page_contextual_help() {
global $enough_theme_uri, $enough_author_uri, $enough_version;
$screen= get_current_screen();
$html= '<dt>%1$s</dt><dd>%2$s</dd>';
$link= '<a href="%1$s" %3$s>%2$s</a>';
$content= '';
/* theme URI */
$content .= sprintf( $html
, __( 'Theme URI', 'enough' )
, sprintf( $link, $enough_theme_uri, $enough_theme_uri, 'target="_self"' )
);
/* AuthorURI */
$content .= sprintf( $html
, __( 'Author', 'enough' )
, sprintf( $link, $enough_author_uri, $enough_author_uri, 'target="_self"' )
);
/* Version */
$content .= sprintf( $html
, __( 'Version', 'enough' )
, $enough_version
);
/* Changelog.txt */
$content .= sprintf( $html
, __( 'Change log text', 'enough' )
, sprintf( $link, get_template_directory_uri() . '/changelog.txt', __( 'Changelog , display new window', 'enough' ), 'target="_blank"' )
, 'target="_blank"'
);
/* readme.txt */
$content .= sprintf( $html
, __( 'Readme text', 'enough' )
, sprintf( $link, get_template_directory_uri() . '/readme.txt', __( 'Readme , display new window', 'enough' ), 'target="_blank"' )
);
$content= '<dl id="enough-help">' . $content . '</dl>';
$screen->add_help_tab( array(
'id'=> 'enough-settings-help',
'title'=> __( 'Enough infomation', 'enough' ),
'content'=> $content
) );
}