Blog 优化记录

No Comments

  刚开始购买域名后就直接使用了国外空间,后面想再换回来时已经不支持.me域名备案了,现在也只能继续使用。无法备案因此无法使用国内CDN,只能使用Cloudflare,但国内访问还是不太好。

  本想找图床存放文章里面的图片,后面看到可使用 Github + Jsdelivr 免费CDN方式保存,并以此方法来保存CSS,Js和Google fonts等静态文件来加速博客访问。修改functions.php将部份加载缓慢静态文件全部替换为Jsdelivr,目前加载比以前快多了.

  使用如下方式进行引用资源

  https://cdn.jsdelivr.net/gh/你的用户名/你的仓库名@发布的版本号/文件路径

https://cdn.jsdelivr.net/gh/Lsanme/wp-img@master/images/T11-2020.jpg

  master分支会有缓存,缓存应该是一天更新一次。如果想进行及时更新,可以将master修改为latest即可.

  通过如下方式,禁用了WP-emoji, WP-embed JS和更换为加载CDN jq

/**
 * Disable the emoji's
 */
 function disable_emojis() {
 remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
 remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
 remove_action( 'wp_print_styles', 'print_emoji_styles' );
 remove_action( 'admin_print_styles', 'print_emoji_styles' );
 remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
 remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
 remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
 add_filter( 'tiny_mce_plugins', 'disable_emojis_tinymce' );
 }
 add_action( 'init', 'disable_emojis' );
/**
 * Filter function used to remove the tinymce emoji plugin.
 */
 function disable_emojis_tinymce( $plugins ) {
 if ( is_array( $plugins ) ) {
 return array_diff( $plugins, array( 'wpemoji' ) );
 } else {
 return array();
 }
 }
/** 
* Change wp default to CDN JQUERY 
*/
function disable_jq() {
    //if not admin , load CDN JQUERY
    if( !is_admin()){
        wp_deregister_script('jquery');
        wp_register_script('jquery', "https://cdn.jsdelivr.net/gh/Lsanme/wp-img@latest/jquery/jquery.js", false, null);
        wp_enqueue_script('jquery');
        wp_deregister_script('jquery-migrate');
        wp_register_script('jquery-migrate', "https://cdn.jsdelivr.net/gh/Lsanme/wp-img@latest/jquery/jquery-migrate.min.js", false, null);
        wp_enqueue_script('jquery-migrate');
    }
}
add_action( 'wp_enqueue_scripts', 'disable_jq' );
/**
* Disable embed
*/

function disable_embeds_init() {
    /* @var WP $wp */
    global $wp;
 
    // Remove the embed query var.
    $wp->public_query_vars = array_diff( $wp->public_query_vars, array(
        'embed',
    ) );
 
    // Remove the REST API endpoint.
    remove_action( 'rest_api_init', 'wp_oembed_register_route' );
 
    // Turn off
    add_filter( 'embed_oembed_discover', '__return_false' );
 
    // Don't filter oEmbed results.
    remove_filter( 'oembed_dataparse', 'wp_filter_oembed_result', 10 );
 
    // Remove oEmbed discovery links.
    remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
 
    // Remove oEmbed-specific JavaScript from the front-end and back-end.
    remove_action( 'wp_head', 'wp_oembed_add_host_js' );
    add_filter( 'tiny_mce_plugins', 'disable_embeds_tiny_mce_plugin' );
 
    // Remove all embeds rewrite rules.
    add_filter( 'rewrite_rules_array', 'disable_embeds_rewrites' );
}
 
add_action( 'init', 'disable_embeds_init', 9999 );
 
/**
 * Removes the 'wpembed' TinyMCE plugin.
 *
 * @since 1.0.0
 *
 * @param array $plugins List of TinyMCE plugins.
 * @return array The modified list.
 */
function disable_embeds_tiny_mce_plugin( $plugins ) {
    return array_diff( $plugins, array( 'wpembed' ) );
}
 
/**
 * Remove all rewrite rules related to embeds.
 *
 * @since 1.2.0
 *
 * @param array $rules WordPress rewrite rules.
 * @return array Rewrite rules without embeds rules.
 */
function disable_embeds_rewrites( $rules ) {
    foreach ( $rules as $rule => $rewrite ) {
        if ( false !== strpos( $rewrite, 'embed=true' ) ) {
            unset( $rules[ $rule ] );
        }
    }
 
    return $rules;
}
 
/**
 * Remove embeds rewrite rules on plugin activation.
 *
 * @since 1.2.0
 */
function disable_embeds_remove_rewrite_rules() {
    add_filter( 'rewrite_rules_array', 'disable_embeds_rewrites' );
    flush_rewrite_rules();
}
 
register_activation_hook( __FILE__, 'disable_embeds_remove_rewrite_rules' );
 
/**
 * Flush rewrite rules on plugin deactivation.
 *
 * @since 1.2.0
 */
function disable_embeds_flush_rewrite_rules() {
    remove_filter( 'rewrite_rules_array', 'disable_embeds_rewrites' );
    flush_rewrite_rules();
}
 
register_deactivation_hook( __FILE__, 'disable_embeds_flush_rewrite_rules' );

APH Prism Syntax Highlighter出现Warning: Cannot modify header information – headers already sent by 错误导致预览更改或发布时,页面无法进行预览显示为空白问题

Warning: Cannot modify header information - headers already sent by (output started at /public_html/wp-content/plugins/aph-prism-highlighter/includes/aphph-admin-editor.php:162) in /public_html/wp-includes/pluggable.php on line 1281 
Warning: Cannot modify header information - headers already sent by (output started at /public_html/wp-content/plugins/aph-prism-highlighter/includes/aphph-admin-editor.php:162) in /public_html/wp-includes/pluggable.php on line 1284

  先停用APH Prism Syntax Highlighter插件,根据错误提示去“插件编辑器”选择APH Prism Syntax Highlighter插件。
选择inclides→aphph-admin-editor.php 找到错误提示的第162行,进行注释掉。

//echo '<span id="aphph-json-user-options" style="display:none">'.json_encode($this->options).'</span>';

  修改首页文章添加分隔线,F12调试里查看样式,在CSS代码里article面添加”.article-after-content” 样式,并找到需要修改template-parts目录下content.php。添加在</div><!– .after-content –>后

<div class="article-after-content"> 
</div><!-- .article-after-content -->
.article-after-content { 
		border-bottom: double; 
		transform:scale(1,1); 
		border-color: #A81010; 
		margin-bottom: 30px; 
}

由于继续使用的经典编辑器,没有必要加载block libary,WordPress 5.0+ remove block-library CSS

//WordPress 5.0+ remove block-library CSS
add_action( 'wp_enqueue_scripts', 'fanly_remove_block_library_css', 100 );
function fanly_remove_block_library_css() {
	wp_dequeue_style( 'wp-block-library' );
}

修改屏蔽登录页面,Location可以修改为任意地址

// Redirect to home page.
add_action('login_enqueue_scripts','login_protection');
function login_protection(){
if($_GET['admin'] != 'lsan')header('Location: https://www.lsan.me/');
}

登录地址就是

https://www.xxxx.com/wp-login.php?admin=lsan

 

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注