个人代码示例-functions.php

<?php
/**
 * Twenty Fourteen functions and definitions
 *
 * Set up the theme and provides some helper functions, which are used in the
 * theme as custom template tags. Others are attached to action and filter
 * hooks in WordPress to change core functionality.
 *
 * When using a child theme you can override certain functions (those wrapped
 * in a function_exists() call) by defining them first in your child theme's
 * functions.php file. The child theme's functions.php file is included before
 * the parent theme's file, so the child theme functions would be used.
 *
 * @link
 * @link
 *
 * Functions that are not pluggable (not wrapped in function_exists()) are
 * instead attached to a filter or action hook.
 *
 * For more information on hooks, actions, and filters,
 * @link
 *
 * @package
 * @subpackage Twenty_Fourteen
 * @since Twenty Fourteen 1.0
 */

/**
 * Set up the content width value based on the theme's design.
 *
 * @see HelloWorld_content_width()
 *
 * @since Twenty Fourteen 1.0
 */

load_theme_textdomain( 'popularsoft', get_template_directory() . '/languages' );

/**
 * 自定义 WordPress 后台顶部导航栏的信息 by Xie Zhiyong
 */  

// 删除系统自带图标 by Xie Zhiyong
function remove_wp_logo() { 
    global $wp_admin_bar; 
    $wp_admin_bar->remove_menu('wp-logo'); 

add_action( 'wp_before_admin_bar_render', 'remove_wp_logo' );
// 删除评论审核选项 by Xie Zhiyong
function remove_comment_bubble() { 
    global $wp_admin_bar; 
    $wp_admin_bar->remove_menu('comments');   

add_action( 'wp_before_admin_bar_render', 'remove_comment_bubble' );
// 删除新项目选项 by Xie Zhiyong
function disable_new_content() { 
    global $wp_admin_bar; 
    $wp_admin_bar->remove_menu('new-content'); 

add_action( 'wp_before_admin_bar_render', 'disable_new_content' );
// 删除更新选项 by Xie Zhiyong
function disable_bar_updates() { 
    global $wp_admin_bar; 
    $wp_admin_bar->remove_menu('updates'); 

add_action( 'wp_before_admin_bar_render', 'disable_bar_updates' );


/**
 * 自定义 WordPress 后台左侧菜单信息 by Xie Zhiyong
 */
function remove_menus() {
  global $menu;
  $restricted = array(__('Dashboard'), __('Posts'), __('Plugins'), __('Media'), __('Links'), __('Pages'), __('Appearance'), __('Tools'), __('Comments'));
  end ($menu);
  while (prev($menu)){
    $value = explode(' ',$menu[key($menu)][0]);
    if(strpos($value[0], '<') === FALSE) {
      if(in_array($value[0] != NULL ? $value[0]:"" , $restricted)){
        unset($menu[key($menu)]);
      }
    }
    else {
      $value2 = explode('<', $value[0]);
      if(in_array($value2[0] != NULL ? $value2[0]:"" , $restricted)){
        unset($menu[key($menu)]);
      }
    }
  }
}

 // 删除指定的左侧菜单 by Xie Zhiyong
if ( is_admin() ) {
 
 add_action('admin_menu', 'remove_menus');
}

// 自定义删除设置的子菜单 by Xie Zhiyong
function remove_submenu() {
    // 删除"设置"下面的子菜单"撰写"  by Xie Zhiyong
    remove_submenu_page( 'options-general.php', 'options-writing.php' );
    // 删除"设置"下面的子菜单"阅读"  by Xie Zhiyong
    remove_submenu_page( 'options-general.php', 'options-reading.php' );
 // 删除"设置"下面的子菜单"讨论"  by Xie Zhiyong
    remove_submenu_page( 'options-general.php', 'options-discussion.php' );
 // 删除"设置"下面的子菜单"多媒体"  by Xie Zhiyong
    remove_submenu_page( 'options-general.php', 'options-media.php' );
 // 删除"设置"下面的子菜单"固定链接"  by Xie Zhiyong
    remove_submenu_page( 'options-general.php', 'options-permalink.php' );
}

// 删除指定的子菜单 by Xie Zhiyong
if ( is_admin() ) {
    add_action('admin_init','remove_submenu');
}


function customTitle($limit) {
 $title = get_the_title($post->ID);
 if(strlen($title) > $limit) {
  $title = substr($title, 0, $limit) . '..........................................................................................................................';
 }else{
  $title = $title . '............................................................................................................................';

 }

 echo $title;
}

/**
 * 自定义WordPress登录图标信息 by Xie Zhiyong
 */
function custom_loginlogo() {
echo '<style type="text/css">
h1 a {background-image: url('.get_bloginfo('template_directory').'/images/logo.png) !important; }
</style>';
}
add_action('login_head', 'custom_loginlogo');


/**
 * 自定义WordPress后台底部版权和版本信息 by Xie Zhiyong
 */

    // 左侧提示信息 by Xie Zhiyong
function custom_admin_footer() {
        echo '';
}
add_filter('admin_footer_text', 'custom_admin_footer');

    // 右侧版本信息 by Xie Zhiyong
add_filter('update_footer', 'right_admin_footer_text', 11);
function right_admin_footer_text($text) {
 $text = " ";
 return $text;}
 
 
 
add_filter('pre_site_transient_update_core',    create_function('$a', "return null;")); // 关闭核心提示
add_filter('pre_site_transient_update_plugins', create_function('$a', "return null;")); // 关闭插件提示
add_filter('pre_site_transient_update_themes',  create_function('$a', "return null;")); // 关闭主题提示 
?>

posted on 2014-07-07 13:14  君子博客  阅读(231)  评论(0编辑  收藏  举报