A-A+

WordPress 相關設定筆記

2015年09月10日 未分类 WordPress 相關設定筆記已关闭评论 阅读 72 次

在升级BulletProof Security时出错:下载失败。 error:0D0C50A1:asn1 encoding routines:ASN1_item_verify:unknown message digest algorithm

原因网上查是openssl的版本太低了

That message indicates some kind of problem with the secure connection, probably caused by having a very old version of OpenSSL somewhere in the loop.

I would do a phpinfo() to get more information about what is on your server. Specifically, you want to find information about what curl versions are running, what the PHP version is, and anything relating to "OpenSSL".

https://codex.wordpress.org/User:Ipstenu/How_to_create_a_phpinfo()_page

 

 

Looks like we will need to upgrade SSL support. We can create an updated Prince build in the next day or two.

 

 

1.停用WordPress updates提醒訊息

如果你覺得WP後台的更新訊息很礙眼,其實可以將它關閉

注意:多力哥是不建議停用這些提醒訊息,因為某些更新可能與網站安全有關。

Disable Theme Updates # 3.0+
//Disable Theme Updates # 3.0+
remove_action( 'load-update-core.php', 'wp_update_themes' );
add_filter( 'pre_site_transient_update_themes', create_function( '$a', "return null;" ) );
wp_clear_scheduled_hook( 'wp_update_themes' );
Disable Plugin Updates #3.0+
//Disable Plugin Updates #3.0+
remove_action( 'load-update-core.php', 'wp_update_plugins' );
add_filter( 'pre_site_transient_update_plugins', create_function( '$a', "return null;" ) );
wp_clear_scheduled_hook( 'wp_update_plugins' );
Diasable Core Updates # 3.0+
//Diasable Core Updates # 3.0+
add_filter( 'pre_site_transient_update_core', create_function( '$a', "return null;" ) );
wp_clear_scheduled_hook( 'wp_version_check' );

2.後台去掉左上角W標誌

function 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);

3.上傳中文檔名

function make_filename_hash($filename) {
$info = pathinfo($filename);
$ext  = empty($info['extension']) ? '' : '.' . $info['extension'];
$name = basename($filename, $ext);
return md5($name) . $ext;
}
add_filter('sanitize_file_name', 'make_filename_hash', 10);

4.自訂後台新聞

//後台自訂新聞
function wpc_dashboard_widget_function() {
    echo '<p>您好,歡迎來到網站控制台。<br/>本網站是由DORIGO IMAGE團隊製作。</p>';
}
function wpc_add_dashboard_widgets() {
    wp_add_dashboard_widget('wp_dashboard_widgets', '網站訊息', 'wpc_dashboard_widget_function');
}
add_action('wp_dashboard_setup', 'wpc_add_dashboard_widgets' );

5.根據頁面類型指定每頁顯示的文章數

function custom_posts_per_page($query){
    if(is_home()){
    $query->set('posts_per_page',6);//首頁每頁顯示8篇文章
    }
    if(is_search()){
        $query->set('posts_per_page',-1);//搜索頁顯示所有匹配的文章,不分頁
    }
    if(is_archive()){
        $query->set('posts_per_page',12);//archive每頁顯示25篇文章
}//endif
}//function
//this adds the function above to the 'pre_get_posts' action
add_action('pre_get_posts','custom_posts_per_page');

6.自訂WP後台上方列選單連結

add_action( 'admin_bar_menu', 'toolbar_link', 999 );
function toolbar_link( $wp_admin_bar ) {
$args = array(
'id'    => 'my_page',
'title' => '我是選單',
'href'  => 'http://dorigo-image.com',
'meta'  => array( 'target' => '_blank' )
);
$wp_admin_bar->add_node( $args );
}

999:排序位置

7.自訂WP後台左方列子選單連結

add_action('admin_menu', 'album_menu');

function album_menu() {
global $submenu;
$url = '放網址';
$submenu['index.php'][] = array('連結名稱', 'manage_options', $url);
}

選單的位置參考(此範例為加到Dashboard):
index.php => Dashboard
edit.php => Posts
upload.php => Media
link-manager.php => Links
edit.php?post_type=page => Pages
edit-comments.php => Comments
themes.php => Appearance
plugins.php => Plugins
users.php => Users
tools.php => Tools
options-general.php => Settings

8.自訂WP後台左方列主選單連結

add_action( 'admin_menu', 'register_custom_menu_link' );
function register_custom_menu_link(){
add_menu_page( 'custom menu link', 'Your Menu Link', 'manage_options', 'any-url', 'wpsites_custom_menu_link', 'dashicons-carrot', 3 );
}
function wpsites_custom_menu_link(){
wp_redirect( 'http://dorigo-image.com', 301 );
exit;
}

參考:
http://codex.wordpress.org/Function_Reference/add_menu_page
http://codex.wordpress.org/Function_Reference/wp_redirect

9.安裝佈景主題失敗

出現:

Warning: unlink(C:WindowsTEMP/795c043fc91788ccdf4ee17b1a402b8a.tmp) [function.unlink]: Permission denied in E:AppServwwwguestwp-adminincludesfile.php on line 457

下載失敗 error:0D0C50A1:asn1 encoding routines:ASN1_item_verify:unknown message digest algorithm

解決方式:

請編輯httpd.conf

找到 #LoadModule ssl_module modules/mod_ssl.so

將註解#去掉,存檔,重啟Apache

10.移除WordPress的 wp_head 中多餘信息

remove_action( 'wp_head', 'wp_generator' ) ; 
remove_action( 'wp_head', 'wlwmanifest_link' ) ; 
remove_action( 'wp_head', 'rsd_link' ) ;

11.Contact Form 7 checkboxes斷行

span.wpcf7-list-item {
display:block;
}

若是要某些checkboxes欄位斷行某些欄位是持續的,請再加以下這行

<div class="noenter">要持續的checkboxes</div>

.noenter span.wpcf7-list-item {
	display: inline-block;
}

12.禁止多個人同時登錄一個賬號

/**
 * Detect if the current user has concurrent sessions
 *
 * @return bool
 */
function pcl_user_has_concurrent_sessions() {
    return ( is_user_logged_in() && count( wp_get_all_sessions() ) > 1 );
}
 
/**
 * Get the user's current session array
 *
 * @return array
 */
function pcl_get_current_session() {
    $sessions = WP_Session_Tokens::get_instance( get_current_user_id() );
 
    return $sessions->get( wp_get_session_token() );
}
 
/**
 * Only allow one session per user
 *
 * If the current user's session has been taken over by a newer
 * session then we will destroy their session automattically and
 * they will have to login again to continue.
 *
 * @action init
 *
 * @return void
 */
function pcl_disallow_account_sharing() {
    if ( ! pcl_user_has_concurrent_sessions() ) {
        return;
    }
 
    $newest  = max( wp_list_pluck( wp_get_all_sessions(), 'login' ) );
    $session = pcl_get_current_session();
 
    if ( $session['login'] === $newest ) {
        wp_destroy_other_sessions();
    } else {
        wp_destroy_current_session();
    }
}
add_action( 'init', 'pcl_disallow_account_sharing' );

13.自動幫文章裡的URL地址生成超鏈接

add_filter('the_content', 'make_clickable');

若要開新視窗

// Make URL Clickable In WordPress (plus target="_blank")

add_filter( 'the_content', 'make_clickable');

function autoblank($text) {
$myurl = 'http://yourname.com';
$external = str_replace('href=', 'target="_blank" href=', $text);
$external = str_replace('target="_blank" href="'.$myurl,%20'href="'.$myurl, $external);
$external = str_replace('target="_blank" href="#',%20'href="#', $external);
$external = str_replace('target = "_blank">', '>', $external);
return $external;
}
add_filter('the_content', 'autoblank');

14.將全站設為需登入才可瀏覽

可看到首頁:

function admin_redirect() {
   if ( !is_front_page() && !is_user_logged_in()) {
       wp_redirect( home_url('wp-login.php') );
       exit;
   }
}
add_action('get_header', 'admin_redirect');

不可看到首頁:

function admin_redirect() {
   if ( !is_user_logged_in()) {
       wp_redirect( home_url('wp-login.php') );
       exit;
   }
}
add_action('get_header', 'admin_redirect');

15.登入後導到前台

function redirect_to_front_page() {
global $redirect_to;
if (!isset($_GET['redirect_to'])) {
$redirect_to = get_option('siteurl');
}
}
add_action('login_form', 'redirect_to_front_page');

16.對特定使用者登入後導到前台

add_filter( 'login_redirect', 'redirect_to_home', 10, 3 );
function redirect_to_home( $redirect_to, $request, $user ) {

    if( $user->ID == 2 ) {
        //If user ID is 2, redirect to home
        return get_home_url();
    } else {
        //If user ID is not 2, leave WordPress handle the redirection as usual
        return $redirect_to;
    }

}

17.禁止一般用戶進入後台

function baw_no_admin_access()
{
if( !current_user_can( 'manage_options' ) ) {
wp_redirect( home_url() );
die();
}
}
add_action( 'admin_init', 'baw_no_admin_access', 1 );

18.Rocket Lazy Load 設定頁面不要延遲加載圖片

add_action( 'wp', 'deactivate_rocket_lazyload_on_single' );
function deactivate_rocket_lazyload_on_single() {
    if ( is_page() ) {
        add_filter( 'do_rocket_lazyload', '__return_false' );
    }
}

18.重設WordPress密碼

將此resetpassword.php檔放到網站根目錄,然後開啟瀏覽器讀取,就可以重設密碼。

設定完成後請記得刪除^^

19.圖片可用子網址

例如:http://img.yourname.com
因為網站在讀取的時候網址會有連線數的限制,如果把網站跟圖片分成兩個網址則可以讓連線數加倍

20.文章列表只顯示標題

編輯wp-content/themes/xxx/index.php

php the_content('Read the rest of this entry »');

替換成:

php
if (is_single()) {
the_content('Read the rest of this entry »');
}
else {//no content, nothing.
}

21.去除後台標題中的— WordPress

//WordPress 去除後台標題中的「—— WordPress」

add_filter('admin_title', 'wpdx_custom_admin_title', 10, 2);
function wpdx_custom_admin_title($admin_title, $title){
return $title.' &lsaquo; '.get_bloginfo('name');
}

22.文章編輯器加入中文字型

add_filter( 'mce_buttons' , 'add_font_selection_to_tinymce' );
function add_font_selection_to_tinymce($buttons) {
     array_push($buttons, 'fontselect');
     return $buttons;
}
add_filter( 'tiny_mce_before_init', 'use_my_fonts_to_tinymce' );
function use_my_fonts_to_tinymce( $initArray ) {
$theme_advanced_fonts .= '標楷體=標楷體;';
$theme_advanced_fonts .= '微軟正黑體=微軟正黑體;';
$theme_advanced_fonts .= '新細明體=新細明體;';
$initArray['font_formats'] = $theme_advanced_fonts;
return $initArray;
}

23.後台文章列表顯示特色圖片

add_theme_support('post-thumbnails');

function ST4_columns_head($defaults) {
$defaults['featured_image'] = '特色圖片';
return $defaults;
}
function ST4_columns_content($column_name, $post_ID) {
if ($column_name == 'featured_image') {
$post_thumbnail_id = get_post_thumbnail_id($post_ID);
if ($post_thumbnail_id) {
$post_thumbnail_img = wp_get_attachment_image_src($post_thumbnail_id);
if ( $post_thumbnail_img[0] ){
echo '<img src="'%20.%20$post_thumbnail_img[0]%20.%20'" />';
}
}
}
}

add_filter('manage_posts_columns', 'ST4_columns_head');
add_action('manage_posts_custom_column', 'ST4_columns_content', 10, 2);

24.文章在行動裝置(寬度小於600px)瀏覽時,顯示LINE分享

<div class="linephone">
<p align=center><a href="http://line.naver.jp/R/msg/text/?<?php%20the_title();%20?>%20%0a<?php%20the_permalink();%20?>"><img src="LINE分享的圖片"></a></p>
</div>

@media screen and (min-width:600px) {
.linephone {display:none;}
}

25.修改後台登錄LOGO和連結

/* WordPress登錄界面Logo和鏈接修改開始 */

function my_custom_login_logo() {
    echo '<style type="text/css">
        h1 a { background-image:url(http://i1.minus.com/if3zR7OA7mNU9.png) !important; background-size: inherit !important; width: 330px; height: 130px; }
    </style>';
}
add_action('login_head', 'my_custom_login_logo');

function custom_loginlogo_url($url) {
    return "http://web.hahasmile.com";
}
add_filter( 'login_headerurl', 'custom_loginlogo_url' );
/* WordPress登錄界面Logo和鏈接修改結束 */

26.wordpress標籤排序數量修改

編輯/wp-includes/category-template.php,搜尋 wp_tag_cloud

function wp_tag_cloud( $args = '' ) {
	$defaults = array(
		'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 40,
		'format' => 'flat', 'separator' => "n", 'orderby' => 'count', 'order' => 'DESC',
		'exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => 'post_tag', 'post_type' => '', 'echo' => true
	);

评论已关闭!

Copyright © 理处言语然自 保留所有权利.   Theme  Ality 京ICP备07032740号

用户登录

分享到: