优化wordpress主题twentysixteen

一、隐藏主题主者

第一步:注释或删除作者显示函数:
twentysixteen_entry_meta()
第二步:修改article{margin-bottom:3.5em;}
第三步:设置文章显示宽度:
entry-content {width: 100%;

twentysixteen主题非常不错,只是让作者时间日期占据左侧,占据左侧空间,压缩了文章内容的显示宽度。
放在底部多好。实现方法如下:

1、打开\wp-content\themes\twentysixteen\template-parts目录下的两个文件:

    • content.php
    • content-single.php

注释掉twentysixteen_entry_meta();这个函数调用。

2、修改\wp-content\themes\twentysixteen\style.css文件,
3465行左右 :

/*默认:*/
.site-main > article {margin-bottom: 7.0em;}
/*修改为:*/
.site-main > article {margin-bottom: 3.5em;}

3572行左右 :

/*默认:*/
body:not(.search-results) article:not(.type-page) .entry-content {float: right;width:71.42857144%;}
/*修改为:*/
body:not(.search-results) article:not(.type-page) .entry-content {float: right;width: 100%;}

修改值如:margin-bottom: 3.5em;及width: 100%;,可依据自己实际需求修改。

二、去掉主题特色图片

注释掉:

<?php the_post_thumbnail(); ?>

三、首页显示文章摘要

去主题编辑器,修改该文件代码:template-parts/content.php

25行:

        <?php
            the_content(
                sprintf(
                    // translators: %s: Post title. 
                    __( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'twentysixteen' ),
                    get_the_title()
                )
            );

注释掉,更改为:

            if(!is_single()) {
                the_excerpt();
                } else {
                the_content(__('(more…)'));
                } 

 

四、 优化文章描述

WP 给摘要的默认 55 个字,进入 functions.php,增加 filter,将其中的 55,改为 150 即可。

/* Excerpt Words */

function my_excerpt_length($length) {

return 150;

}

add_filter('excerpt_length', 'my_excerpt_length');