function.php檔案常用設定

來源:互聯網
上載者:User

標籤:

<?php// 一、不要長時間連結function get_ssl_avatar($avatar) { //$avatar = preg_replace('/.*/avatar/(.*)?s=([d]+)&.*/','<img class="avatar avatar-$2" src="https://secure.gravatar.com/avatar/$1?s=$2" alt="" width="$2" height="$2" />',$avatar);   return $avatar;};add_filter('get_avatar', 'get_ssl_avatar');// 二、縮圖添加if ( function_exists( 'add_theme_support' ) )   add_theme_support( 'post-thumbnails' );// 三、擷取內容的第一張圖function catch_that_image() {global $post, $posts;$first_img = '';ob_start();ob_end_clean();$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);//四、擷取文章中第一張圖片的路徑並輸出$first_img = $matches [1] [0];//五、如果文章無圖片,擷取自訂圖片if(empty($first_img)){ //Defines a default image$first_img = "/images/default.jpg";//請自行設定一張default.jpg圖片}return $first_img;}//六、禁止系統和外掛程式更新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;")); // 關閉主題提示remove_action('admin_init', '_maybe_update_core');    // 禁止 WordPress 檢查更新remove_action('admin_init', '_maybe_update_plugins'); // 禁止 WordPress 更新外掛程式remove_action('admin_init', '_maybe_update_themes');  // 禁止 WordPress 更新主題//七、設定摘要字數function custom_excerpt_length( $length ) {    return 100;}add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );//八、分頁外掛程式//調用分頁方法  <div class="page_navi fqj_fenye">   php par_pagenavi(9); </div>中間加php標記符號function par_pagenavi($range = 9){        global $paged, $wp_query;        if ( !$max_page ) {$max_page = $wp_query->max_num_pages;}        if($max_page > 1){if(!$paged){$paged = 1;}        if($paged != 1){echo "<a href='" . get_pagenum_link(1) . "' class='extend' title='跳轉到首頁'> 返回首頁 </a>";}        previous_posts_link(' 上一頁 ');        if($max_page > $range){            if($paged < $range){for($i = 1; $i <= ($range + 1); $i++){echo "<a href='" . get_pagenum_link($i) ."'";            if($i==$paged)echo " class='current'";echo ">$i</a>";}}        elseif($paged >= ($max_page - ceil(($range/2)))){            for($i = $max_page - $range; $i <= $max_page; $i++){echo "<a href='" . get_pagenum_link($i) ."'";            if($i==$paged)echo " class='current'";echo ">$i</a>";}}        elseif($paged >= $range && $paged < ($max_page - ceil(($range/2)))){            for($i = ($paged - ceil($range/2)); $i <= ($paged + ceil(($range/2))); $i++){echo "<a href='" . get_pagenum_link($i) ."'";if($i==$paged) echo " class='current'";echo ">$i</a>";}}}        else{for($i = 1; $i <= $max_page; $i++){echo "<a href='" . get_pagenum_link($i) ."'";        if($i==$paged)echo " class='current'";echo ">$i</a>";}}        next_posts_link(' 下一頁 ');        if($paged != $max_page){echo "<a href='" . get_pagenum_link($max_page) . "' class='extend' title='跳轉到最後一頁'> 最後一頁 </a>";}}    }//九、屏蔽後台更新功能function wp_hide_nag() {    remove_action( 'admin_notices', 'update_nag', 3 );}add_action('admin_menu','wp_hide_nag');//十、屏蔽後台logofunction annointed_admin_bar_remove() {        global $wp_admin_bar;        /* Remove their stuff */        $wp_admin_bar->remove_menu('wp-logo');}add_action('wp_before_admin_bar_render', 'annointed_admin_bar_remove', 0);//十一、文章首行縮排// function Bing_text_indent($text){//  $return = str_replace('<p', '<p style="text-indent:2em;"',$text);//  return $return;//  }//  add_filter('the_content','Bing_text_indent');// 十二、替換後台管理員頭像function wpyou_get_ssl_avatar($avatar) {$avatar = preg_replace('/.*\/avatar\/(.*)\?s=([\d]+)&.*/','<img src="https://secure.gravatar.com/avatar/$1?s=$2" class="avatar avatar-$2" height="$2" width="$2">',$avatar);return $avatar;}add_filter('get_avatar', 'wpyou_get_ssl_avatar');//十三、WordPress 後台管理菜單名稱重新命名的方法function change_post_menu_label() {global $menu;$menu[2][0] = '後台首頁';}function change_post_object_label() {}add_action( 'init', 'change_post_object_label' );add_action( 'admin_menu', 'change_post_menu_label' );//十四、移除 WordPress 儀錶盤歡迎面板remove_action('welcome_panel', 'wp_welcome_panel');//十五、麵包屑外掛程式  調用外掛程式方法 php if(function_exists('cmp_breadcrumbs')) cmp_breadcrumbs(); 前後加php標記符號function cmp_breadcrumbs() {    $delimiter = '>'; // 分隔字元    $before = '<span class="current">'; // 在當前連結前插入    $after = '</span>'; // 在當前連結後插入    if ( !is_home() && !is_front_page() || is_paged() ) {        echo '<div itemscope itemtype="http://schema.org/WebPage" id="crumbs">'.__( '當前位置:' , 'cmp' );        global $post;        $homeLink = home_url();        echo ' <a itemprop="breadcrumb" href="' . $homeLink . '">' . __( '首頁' , 'cmp' ) . '</a> ' . $delimiter . ' ';        if ( is_category() ) { // 分類 存檔            global $wp_query;            $cat_obj = $wp_query->get_queried_object();            $thisCat = $cat_obj->term_id;            $thisCat = get_category($thisCat);            $parentCat = get_category($thisCat->parent);            if ($thisCat->parent != 0){                $cat_code = get_category_parents($parentCat, TRUE, ' ' . $delimiter . ' ');                echo $cat_code = str_replace ('<a','<a itemprop="breadcrumb"', $cat_code );            }            echo $before . '' . single_cat_title('', false) . '' . $after;        } elseif ( is_day() ) { // 天 存檔            echo '<a itemprop="breadcrumb" href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';            echo '<a itemprop="breadcrumb"  href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('F') . '</a> ' . $delimiter . ' ';            echo $before . get_the_time('d') . $after;        } elseif ( is_month() ) { // 月 存檔            echo '<a itemprop="breadcrumb" href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';            echo $before . get_the_time('F') . $after;        } elseif ( is_year() ) { // 年 存檔            echo $before . get_the_time('Y') . $after;        } elseif ( is_single() && !is_attachment() ) { // 文章            if ( get_post_type() != 'post' ) { // 自訂文章類型                $post_type = get_post_type_object(get_post_type());                $slug = $post_type->rewrite;                echo '<a itemprop="breadcrumb" href="' . $homeLink . '/' . $slug['slug'] . '/">' . $post_type->labels->singular_name . '</a> ' . $delimiter . ' ';                echo $before . get_the_title() . $after;            } else { // 文章 post                $cat = get_the_category(); $cat = $cat[0];                $cat_code = get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');                echo $cat_code = str_replace ('<a','<a itemprop="breadcrumb"', $cat_code );                echo $before . get_the_title() . $after;            }        } elseif ( !is_single() && !is_page() && get_post_type() != 'post' ) {            $post_type = get_post_type_object(get_post_type());            echo $before . $post_type->labels->singular_name . $after;        } elseif ( is_attachment() ) { // 附件            $parent = get_post($post->post_parent);            $cat = get_the_category($parent->ID); $cat = $cat[0];            echo '<a itemprop="breadcrumb" href="' . get_permalink($parent) . '">' . $parent->post_title . '</a> ' . $delimiter . ' ';            echo $before . get_the_title() . $after;        } elseif ( is_page() && !$post->post_parent ) { // 頁面            echo $before . get_the_title() . $after;        } elseif ( is_page() && $post->post_parent ) { // 父級頁面            $parent_id  = $post->post_parent;            $breadcrumbs = array();            while ($parent_id) {                $page = get_page($parent_id);                $breadcrumbs[] = '<a itemprop="breadcrumb" href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';                $parent_id  = $page->post_parent;            }            $breadcrumbs = array_reverse($breadcrumbs);            foreach ($breadcrumbs as $crumb) echo $crumb . ' ' . $delimiter . ' ';            echo $before . get_the_title() . $after;        } elseif ( is_search() ) { // 搜尋結果            echo $before ;            printf( __( 'Search Results for: %s', 'cmp' ),  get_search_query() );            echo  $after;        } elseif ( is_tag() ) { //標籤 存檔            echo $before ;            printf( __( 'Tag Archives: %s', 'cmp' ), single_tag_title( '', false ) );            echo  $after;        } elseif ( is_author() ) { // 作者存檔            global $author;            $userdata = get_userdata($author);            echo $before ;            printf( __( 'Author Archives: %s', 'cmp' ),  $userdata->display_name );            echo  $after;        } elseif ( is_404() ) { // 404 頁面            echo $before;            _e( 'Not Found', 'cmp' );            echo  $after;        }        if ( get_query_var('paged') ) { // 分頁            if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() )                echo sprintf( __( '( 第 %s 頁)', 'cmp' ), get_query_var('paged') );        }        echo '</div>';    }}//添加後台外觀菜單//if ( function_exists('register_sidebar') )register_sidebar(array('before_widget' //=> '<div class=”sidebox”> ','after_widget' => '</div>','before_title' => '<h2>','after_title' => '</h2>',));?>

function.php檔案常用設定

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.