WordPress context help tag: The key to improving user experience
The small "Help" tab in the upper right corner of the WordPress admin panel will display useful information and usage of each admin page. This is the context help tab. Its "context" feature is that the information displayed is related to the currently viewed management page. For example, clicking on the article editing page will display instructions for customizing the screen display, entering titles and content, inserting media files, and enabling or disabling comments and pingbacks.
For plugin or theme developers, this helps to provide users with fast documentation, thereby reducing customer support issues. If you want to learn topic development, you can check out the WordPress theme development course on SitePoint Premium.
Custom article types and topics or plugin settings pages do not have default context help tags. This tutorial will guide you how to add this feature to the above administration page.
Add context help tag to the article type screen
The and add_help_tab()
methods of the set_help_sidebar()
WP_Screen class are used to add context help menus and sidebars to the help tab of the admin page.
The following function will add three menus to the context help label of the management page:
function sp_help_tabs() { $screen = get_current_screen(); $screen->add_help_tab( [ 'id' => 'sp_overview', 'title' => '概述', 'content' => '<p>此处为您的插件或主题概述</p>' ] ); $screen->add_help_tab( [ 'id' => 'sp_faq', 'title' => '常见问题', 'content' => '<p>此处为常见问题及其解答</p>' ] ); $screen->add_help_tab( [ 'id' => 'sp_support', 'title' => '支持', 'content' => '<p>如需支持,请通过 me@w3guy.com 联系我们</p>' ] ); }
get_current_screen()
function returns the WP_Screen object of the currently viewed management page, and its value is saved to the $screen variable. The add_help_tab()
method accepts the following parameters and is called three times to add three menus to the context help of the screen:
id
: The unique ID of the tag must be HTML-safe and should not contain spaces. title
: The title of the label. content
: The content of the help tag can be plain text or HTML. callback
: The function to be called to output the contents of this page. content
and callback
can be used in combination, the former is displayed before the latter. Anonymous or named functions can be used as callbacks.
To add a sidebar to the context help of the screen, use WP_Screen's set_help_sidebar()
method:
$screen->set_help_sidebar( '这是您将添加到侧边栏的内容。' );
To add the context help tag to the Books custom article type screen, attach the sp_help_tabs
function to the load-edit.php
and load-post.php
actions. Then, do a condition check to make sure you are in the Books CPT:
add_action( "load-edit.php", 'sp_help_tabs' ); add_action( "load-post.php", 'sp_help_tabs' ); // ... (sp_help_tabs 函数代码) ...
Add a context help tag to the settings page
The process of adding a help label to a plugin or theme settings page is almost the same as the process of adding the article type screen above. The only difference is which action hook will the function that contains the context help label settings be hooked to, in this case the add_menu_page()
returned by hook_suffix
(if you created a top-level menu) or add_submenu_page()
(if it is a submenu ).
Summary
This tutorial explains the concept, importance of context help tags and how to implement it in the WordPress article type and plugin/theme settings page screen, hoping this will reduce your support issues and technical customer support!
(The following is the FAQ part, and the pseudo-original processing has been carried out)
FAQs about custom article type context help tags (FAQ)
What does context help mean in custom article types?
Context help plays a crucial role in customizing article types as it provides instant help and guidance to users. It helps users understand the capabilities of different fields and options, thereby enhancing their overall experience. Context help can be in the form of tooltips, pop-ups, or help tags, providing relevant information when the user needs it. This reduces the need for users to leave their current tasks to seek help, thereby increasing efficiency and productivity.
How to add context help tags to my custom post type?
Adding context help tags to custom article types involves several steps. First, you need to register your custom post type using the register_post_type()
function. You can then add the help tag using the add_help_tab()
method of the WP_Screen class. This method accepts an array of parameters that define the title and content of the help label. You can also add multiple help tags if needed.
Can I customize the content of the context help tag?
Yes, you can customize the content of the context help tag as needed. You can include text, links, images, and even videos in the Help Tags. This allows you to provide users with comprehensive and detailed help, enhancing their understanding and use of custom article types.
(Subsequent FAQ issues, synonyms replaced and sentence adjustments have been made according to the original text, keeping the original meaning unchanged)
... (The rest of the FAQ questions, similar treatment) ...
The above is the detailed content of Adding a Contextual Help Tab to Custom Post Type Screens. For more information, please follow other related articles on the PHP Chinese website!