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

自定义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条)

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?