最常用的WordPress后台提示信息:add_action函数大全

        我们在wordpress开发中尤其是使用中,常常会用到一些后台提示信息,方便提醒使用者一些提示信息的,所以在不同的位置需要有更多的提示来加强后台的使用体验,这里大挖总结整理了一些比较常用的后台信息提供函数,方便大家使用。

wordpress 后台指定页面顶部添加提示信息:add_action

//提示信息
function pageNotice(){
	echo '<div class="updated">'
		. '<p>这里是提示信息</p>'
		. '<p>这里是警告信息</p>'
		. '</div>';
}
 
//add_action('admin_notices', 'pageNotice');/这是后台全局提示
add_action( 'admin_head-post.php', 'pageNotice' );//文章编辑页面
add_action( 'admin_head-post-new.php', 'pageNotice' );//文章/页面 新建
add_action( 'admin_head-edit.php', 'pageNotice' );//文章列表

WordPress 给“特色图像”模块添加提示说明文字

/**
 * WordPress 给“特色图像”模块添加说明文字

 */
add_filter( 'admin_post_thumbnail_html', 'add_featured_image_instruction');
function add_featured_image_instruction( $content ) {
	return $content .= '<p>特色图像将用来作为这篇文章的缩略图,请务必为文章选择一个特色图像。</p>';
}

在 WordPress 后台文章编辑器的上方或下方添加提示内容

function below_the_title() {
    echo '<h3>在编辑器上方添加的提示内容</h3>';
}
add_action( 'edit_form_after_title', 'below_the_title' );
 
function below_the_editor() {
    echo '<h4>在编辑器下方添加的提示内容</h4>';
}
add_action( 'edit_form_after_editor', 'below_the_editor' );

wordpress 后台登录页面增加提示语

//自定义登录页底部信息
function custom_html() 
{
    echo '<p style="text-align:center;color:#ff0000; ">注意:这是一段警告,这是一段警告</p>';
 
}
add_action('login_footer', 'custom_html');

WordPress 后台添加提示框

/**
  *WordPress 后台添加提示框
*/
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' );

WordPress中提醒安装插件功能:

        当你需要提示用户需安装某款插件来实现网站某些功能的时候,相信本篇文章将会帮助你

只需要把上面的代码放入 functions.php 文件中即可,把相应插件换成你想要 WordPress 主题安装的插件,实现的效果如下

当你下载并安装了相应的插件之后,这些提示文字变自动消失了,怎么样,是不是很方便。

//WordPress中提醒安装插件
function adam_plugins_messages(){
    $plugin_messages = array();
    include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
 
    //建议安装 Custom Post Type Permalinks 插件
    if( !is_plugin_active( 'custom-post-type-permalinks/custom-post-type-permalinks.php' ) ) $plugin_messages[] = '建议安装并启用 Custom Post Type Permalinks 插件,作用是设置产品栏目的固定链接 | 点此搜索并下载此插件';
 
    //建议安装 WP No Base Permalin 插件
    if( !is_plugin_active( 'wp-no-base-permalink/wp-no-base-permalink.php' ) ) $plugin_messages[] = '建议安装并启用 WP No Base Permalink 插件,去除链接中的category目录和tag目录 | 点此搜索并下载此插件';
 
    if( count( $plugin_messages ) > 0 ){
        echo '';
        foreach( $plugin_messages as $message ) echo '' . $message . '';
        echo '';
    }
}
add_action( 'admin_notices', 'adam_plugins_messages' );
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值