RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
wordpress头部 wordpress设置头像

如何给WORDPRESS主题添加自定义头部图像

1、首先设置好自己的本地头像头像avatar.jpg(80*80px),把他上传到主题images目录下

成都创新互联专注于企业全网整合营销推广、网站重做改版、临桂网站定制设计、自适应品牌网站建设、H5页面制作商城开发、集团公司官网建设、外贸网站建设、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为临桂等各大城市提供网站开发制作服务。

2.修改主题函数模版,将下列代码粘贴到主题functions.php中去。

/设置默认头像

add_filter( 'avatar_defaults', 'custom_gravatar' );

function custom_gravatar($avatar_defaults) { $myavatar=get_bloginfo('template_url') . '/images/avatar.jpg';

$avatar_defaults[$myavatar] = "2015新头像"; return $avatar_defaults; }

3、这样我们就添加好了新的默认头像“2015新头像”,赶快到后台设置他作为默认头像。

如何给WordPress主题添加自定义头部图像

添加代码到Functions.php文件

你的主题中应该有一个功能函数文件functions.php,如果没有则自建一个,然后复制并粘贴以下代码进去:

?php

//Check see if the customisetheme_setup exists

if ( !function_exists('customisetheme_setup') ):

//Any theme customisations contained in this function

function customisetheme_setup() {

//Define default header image

define( 'HEADER_IMAGE', '%s/header/default.jpg' );

//Define the width and height of our header image

define( 'HEADER_IMAGE_WIDTH', apply_filters( 'customisetheme_header_image_width',960 ) );

define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'customisetheme_header_image_height',220 ) );

//Turn off text inside the header image

define( 'NO_HEADER_TEXT', true );

//Don't forget this, it adds the functionality to the admin menu

add_custom_image_header( '', 'customisetheme_admin_header_style' );

//Set some custom header images, add as many as you like

//%s is a placeholder for your theme directory

$customHeaders = array (

//Image 1

'perfectbeach' = array (

'url' = '%s/header/default.jpg',

'thumbnail_url' = '%s/header/thumbnails/pb-thumbnail.jpg',

'description' = __( 'Perfect Beach', 'customisetheme' )

),

//Image 2

'tiger' = array (

'url' = '%s/header/tiger.jpg',

'thumbnail_url' = '%s/header/thumbnails/tiger-thumbnail.jpg',

'description' = __( 'Tiger', 'customisetheme' )

),

//Image 3

'lunar' = array (

'url' = '%s/header/lunar.jpg',

'thumbnail_url' = '%s/header/thumbnails/lunar-thumbnail.jpg',

'description' = __( 'Lunar', 'customisetheme' )

)

);

//Register the images with WordPress

register_default_headers($customHeaders);

}

endif;

if ( ! function_exists( 'customisetheme_admin_header_style' ) ) :

//Function fired and inline styles added to the admin panel

//Customise as required

function customisetheme_admin_header_style() {

?

style type="text/css"

#wpbody-content #headimg {

height: ?php echo header_image_height; ?px;

width: ?php echo header_image_width; ?px;

border: 1px solid #333;

}

/style

?php

}

endif;

//Execute our custom theme functionality

add_action( 'after_setup_theme', 'customisetheme_setup' );

?

说明:上面代码中设定了三张头部图像,分别为default.jpg、tiger.jpg、lunar.jpg以及它们各自的缩略图(分别为tiger-thumbnail.jpg、pb-thumbnail.jpg、lunar-thumbnail.jpg)。你可以自己制作这些图像(包括它们相应的缩略图),然后将这些图像都放到主题目录下面的header文件夹(没有则自建一个)中。其中,

Default.jpg 是默认显示的头部图像,名称可自定

960 是默认头部图像的宽度

220 是默认头部图像的高度

保存好上面的代码之后,你会在WordPress后台的左侧【外观】菜单下看到一个叫做【顶部】的子菜单,就跟WordPress默认主题Twenty Ten或Twenty Eleven一样,打开【顶部】菜单即可看到自定义顶部图像选项页面:

wordpress头部标题设置代码

你的模板中一定有这段代码吧?php if ( is_category() ) { ?title?php single_cat_title(); ? | ?php bloginfo('name'); ?/title?php } ?,wordpress在选择标题的时候,它会做一个判断的。如果你篇文章不在某个分类下面,它会直接显示,文章--网站标题的。所以,先把分类分好,自然就出来。而且,这样的标题对seo也没影响的.

如何移除WordPress头部多出window

如果你更新到 wordpress 的 4.2 版本,查看网页源代码你会发现 WordPress 会自动在加载一段用于支持 emjo 表情的脚本如下图所示(JS+CSS)。对于大部分人来说,这个是十分鸡肋的功能,会影响网站的加载速度,js放在网站头部对网站的优化也很不好。那么如何去掉呢?可以通过主题目录下的functions.php 文件来进行移除。

可以在wordpress后台所在的主题(也可以通过ftp传送本地修改)functions.php加入如下代码即可:(修改前请做好网站备份)

//去除window._wpemojiSettings

remove_action( 'admin_print_scripts',    'print_emoji_detection_script');

remove_action( 'admin_print_styles',    'print_emoji_styles');

remove_action( 'wp_head',        'print_emoji_detection_script',    7);

remove_action( 'wp_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');

PS:如果直接复制代码添加不成功,是标点符号的大小写问题。请切换小写修改标点符号再保存。


文章标题:wordpress头部 wordpress设置头像
转载来于:http://scyingshan.cn/article/dogcooh.html