Home >Backend Development >PHP Tutorial >Sharing code examples for adding prompt boxes to the WordPress editing backend, _PHP tutorial
WordPress 3.5 has added a new prompt box function, which allows you to create a prompt box and point it to any element, such as Example below:
This article will teach you how to create such a prompt box.
First you need to add the script of the prompt box so that you can use the JS method of the prompt box.
//挂载提示框脚本 function Bing_admin_pointer_enqueue_scripts(){ wp_enqueue_style( 'wp-pointer' ); wp_enqueue_script( 'wp-pointer' ); } add_action( 'admin_enqueue_scripts', 'Bing_admin_pointer_enqueue_scripts' );
Then use the pointer() method to create a simple tooltip:
/** *WordPress 后台添加提示框 *http://www.endskin.com/admin-help-box/ */ function Bing_add_pointer_scripts(){ $content = '<h3>请设置主题</h3>'; $content .= '<p>请为新主题进行简单的配置!'; ?> <script type="text/javascript"> //<![CDATA[ jQuery(document).ready(function($){ $('#menu-appearance').pointer({//可以指向任何元素 content: '<?php echo $content; ?>', position: { edge: 'left', align: 'center' }, close: function(){ //提示框打开之后做的事情 } }).pointer('open'); }); //]]> </script> <?php } add_action( 'admin_print_footer_scripts', 'Bing_add_pointer_scripts' );<br />
Comprehensive code:
/** *WordPress 后台添加提示框 *http://www.endskin.com/admin-help-box/ */ function Bing_add_pointer_scripts(){ $content = '<h3>请设置主题</h3>'; $content .= '<p>请为新主题进行简单的配置!'; ?> <script type="text/javascript"> //<![CDATA[ jQuery(document).ready(function($){ $('#menu-appearance').pointer({//可以指向任何元素 content: '<?php echo $content; ?>', position: { edge: 'left', align: 'center' }, close: function(){ //提示框打开之后做的事情 } }).pointer('open'); }); //]]> </script> <?php } add_action( 'admin_print_footer_scripts', 'Bing_add_pointer_scripts' ); //挂载提示框脚本 function Bing_admin_pointer_enqueue_scripts(){ wp_enqueue_style( 'wp-pointer' ); wp_enqueue_script( 'wp-pointer' ); } add_action( 'admin_enqueue_scripts', 'Bing_admin_pointer_enqueue_scripts' );