自定义 wordpress 主题,图片不显示?
Custom wordpress theme, images not displaying?
所以我试图寻找解决方案:
custom wordpress theme: layout images not displaying
它对我不起作用。
我的主题目录是
wp-content/themes/fearnothing/
并由这些文件组成
/css(folder)
/js (folder)
/images (folder)
header.php
index.php
function.php
footer.php
style.css
hrtbrk.gif
hrtbrk.png
css 文件夹包含
fearnothing.css
js 文件夹为空
fearnothing.js
我的 header.php 有以下代码:
<!DOCTYPE html>
<html>
<head>
<title>example title</title>
<?php wp_head(); ?>
</head>
<body>
<img class ="nightsky" src="wp-content/themes/fearnothing/hrtbrk.png" alt ="3">
functions.php
<?php
function fearnothing_script_enqueue(){
wp_enqueue_style('customstyle', get_template_directory_uri().'/css/fearnothing.css',array(), '1.1.2', 'all');
}
add_action('wp_enqueue_scripts', 'fearnothing_script_enqueue');
fearnothing.css
html,body{
background: black;
color: #8c0707;
font-family: Courier,Courier New,Lucida Sans Typewriter,Lucida Typewriter,monospace;
font-size: 10px;
cursor: pointer;
}
.nightsky{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 500px;
height: 500px;
}
我正在尝试添加 gif,但没有成功。所以我尝试了一张图片。我用 html 离线测试了我的代码,它工作正常吗?
编辑
我在主题中添加了一个图像文件夹。
在 wp-content
上方添加主页 URL
<img class ="nightsky" src="<?php echo home_url(); ?>/wp-content/themes/fearnothing/hrtbrk.png" alt ="3">
尝试使用 get_stylesheet_directory_uri()
函数
<img class="nightsky" src="<?php echo get_stylesheet_directory_uri()?>/hrtbrk.png" alt="">
引用link
试试下面的选项。
<img class ="nightsky" src="<?php echo site_url(); ?>/wp-content/themes/fearnothing/hrtbrk.png" alt ="3">
OR
<img class ="nightsky" src="<?php echo home_url(); ?>/wp-content/themes/fearnothing/hrtbrk.png" alt ="3">
尝试使用 get_template_directory()
函数
<img class="nightsky" src="<?php echo get_stylesheet_directory_uri()?>/hrtbrk.png" alt="">
所以我想出了一个可行的方法,但实际上并不是我想要的方法。
我需要直接通过wordpress media上传图片。
存储在/wp-content/uploads
我希望图像位于主题文件夹中 wp-content/themes/fearnothing/images
但由于某些奇怪的原因,文件已损坏。 (因此图像文件损坏)
直接上传到上传文件夹后,我就可以使用原来的标签了。
<img class ="nightsky" src="https://mywesbiteurl.com/wp-content/uploads/2018/12/hrtbrk.png" alt="" >
所以我试图寻找解决方案: custom wordpress theme: layout images not displaying
它对我不起作用。
我的主题目录是
wp-content/themes/fearnothing/
并由这些文件组成
/css(folder)
/js (folder)
/images (folder)
header.php
index.php
function.php
footer.php
style.css
hrtbrk.gif
hrtbrk.png
css 文件夹包含
fearnothing.css
js 文件夹为空
fearnothing.js
我的 header.php 有以下代码:
<!DOCTYPE html>
<html>
<head>
<title>example title</title>
<?php wp_head(); ?>
</head>
<body>
<img class ="nightsky" src="wp-content/themes/fearnothing/hrtbrk.png" alt ="3">
functions.php
<?php
function fearnothing_script_enqueue(){
wp_enqueue_style('customstyle', get_template_directory_uri().'/css/fearnothing.css',array(), '1.1.2', 'all');
}
add_action('wp_enqueue_scripts', 'fearnothing_script_enqueue');
fearnothing.css
html,body{
background: black;
color: #8c0707;
font-family: Courier,Courier New,Lucida Sans Typewriter,Lucida Typewriter,monospace;
font-size: 10px;
cursor: pointer;
}
.nightsky{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 500px;
height: 500px;
}
我正在尝试添加 gif,但没有成功。所以我尝试了一张图片。我用 html 离线测试了我的代码,它工作正常吗?
编辑 我在主题中添加了一个图像文件夹。
在 wp-content
上方添加主页 URL<img class ="nightsky" src="<?php echo home_url(); ?>/wp-content/themes/fearnothing/hrtbrk.png" alt ="3">
尝试使用 get_stylesheet_directory_uri()
函数
<img class="nightsky" src="<?php echo get_stylesheet_directory_uri()?>/hrtbrk.png" alt="">
引用link
试试下面的选项。
<img class ="nightsky" src="<?php echo site_url(); ?>/wp-content/themes/fearnothing/hrtbrk.png" alt ="3">
OR
<img class ="nightsky" src="<?php echo home_url(); ?>/wp-content/themes/fearnothing/hrtbrk.png" alt ="3">
尝试使用 get_template_directory()
函数
<img class="nightsky" src="<?php echo get_stylesheet_directory_uri()?>/hrtbrk.png" alt="">
所以我想出了一个可行的方法,但实际上并不是我想要的方法。
我需要直接通过wordpress media上传图片。
存储在/wp-content/uploads
我希望图像位于主题文件夹中 wp-content/themes/fearnothing/images
但由于某些奇怪的原因,文件已损坏。 (因此图像文件损坏)
直接上传到上传文件夹后,我就可以使用原来的标签了。
<img class ="nightsky" src="https://mywesbiteurl.com/wp-content/uploads/2018/12/hrtbrk.png" alt="" >