wordpress如何在标题上面加图片

wordpress如何在标题上面加图片,第1张

wordpress在标题上面加图片方法如下:

1、后台添加文本小工具:

登陆Wordpress后台,外观,小工具,把文本工具移动到右边的显示栏里面,直接拖拽即可,移动到想放的地方再松手

2、添加文件源:

这点就是让Wordpress的媒体库想要展示的图片,一般是在多媒体里面,然后添加媒体直接上传想要的图片,上传完以后,点击图片,获取图片在网站程序内的文件url,如下图所示:

3、设置文本工具展示图片:

这个时候,在文本小工具内编辑,标题可以写上展示的信息。

添加代码到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一样,打开【顶部】菜单即可看到自定义顶部图像选项页面:


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11743114.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-18
下一篇2023-05-18

发表评论

登录后才能评论

评论列表(0条)

    保存