dongtiao2976 2018-12-10 10:59
浏览 246
已采纳

自定义wordpress主题,图片不显示?

So I attempted to look for a solution: custom wordpress theme: layout images not displaying

It did not work for me.

enter image description here

My directory for my theme is

wp-content/themes/fearnothing/

and consist of these files

/css(folder) 
/js (folder)
/images (folder)
header.php
index.php
function.php
footer.php
style.css
hrtbrk.gif
hrtbrk.png

css folder contains

fearnothing.css

js folder is empty

fearnothing.js

My header.php has the following code:

    <!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;
        }

I'm trying to add the gif but it did not work. so I tried an image instead. I tested my code offline with html and it works fine?

EDIT I added a images folder to my theme where the theme would be located.

  • 写回答

5条回答 默认 最新

  • du656637962 2018-12-10 21:20
    关注

    So I figured out a method that works which is not really how I wanted it to work.

    I needed to upload the image directly through wordpress media.

    Which is stored in /wp-content/uploads I wanted the images to be inside the themes folder wp-content/themes/fearnothing/images

    but for some odd reason the files are being corrupted. (hence the broken image file)

    After uploading directly to the uploads folder I was able to use the tag I had originally.

    <img  class ="nightsky" src="https://mywesbiteurl.com/wp-content/uploads/2018/12/hrtbrk.png" alt="" >
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 C语言PE文件遍历节表
  • ¥30 backtrader对于期货交易的现金和资产计算的问题
  • ¥15 求C# .net4.8小报表工具
  • ¥15 安装虚拟机时出现问题
  • ¥15 Selenium+docker Chrome不能运行
  • ¥15 mac电脑,安装charles后无法正常抓包
  • ¥18 visio打开文件一直显示文件未找到
  • ¥15 请教一下,openwrt如何让同一usb储存设备拔插后设备符号不变?
  • ¥50 使用quartz框架进行分布式任务定时调度,启动了两个实例,但是只有一个实例参与调度,另外一个实例没有参与调度,不知道是为什么?请各位帮助看一下原因!!
  • ¥50 怎么获取Ace Editor中的python代码后怎么调用Skulpt执行代码