首页 > 解决方案 > Wordpress 的指针

问题描述

我在我的子主题中的 functions.php 文件中插入了一个代码,以在 wordpress 管理区域中创建一个指针。代码是这样的:

add_action( 'admin_enqueue_scripts', 'my_admin_enqueue_scripts' );
function my_admin_enqueue_scripts() {
    wp_enqueue_style( 'wp-pointer' );
    wp_enqueue_script( 'wp-pointer' );
    add_action( 'admin_print_footer_scripts', 'my_admin_print_footer_scripts' );
}
function my_admin_print_footer_scripts() {
    $pointer_content = '<h3>Notice:</h3>';
    $pointer_content .= '<p>This is a message that I will still customize"</strong>.</p>';
?>
    <script type="text/javascript">
    //<![CDATA[
    jQuery(document).ready( function($) {
     $('#wp-admin-bar-breeze-topbar').pointer({
         content: '<?php echo $pointer_content; ?>',
         position: 'top',
         close: function() {
             // Once the close button is hit
         }
       }).pointer('open');
    });
    //]]>
    </script>
<?php
}

该代码完美运行。我需要的是,当用户单击关闭按钮时,该指针不再出现。我应该在这里添加什么来解决这个问题吗?非常感谢!

标签: javascriptphpwordpresspointers

解决方案


这应该得到它:

<script type="text/javascript">
jQuery(document).ready( function($) {
     $('#wp-admin-bar-breeze-topbar').pointer({
         content: '<?php echo $pointer_content; ?>',
         position: 'top',
         }
       }).pointer('open');
    $('#wp-admin-bar-breeze-topbar').click(function(){
        $(this).remove();
    });

    });
</script>

推荐阅读