Support » Developing with WordPress » Problem 404 with linking theme files in WordPress when creating your own theme

  • Resolved nsog8sm43x

    (@nsog8sm43x)


    I create my own theme for WordPress. I have linked the photos as indicated in the official documentation, but I get an error. Pictures are in place.

    This is my code.

    <img src="<?php echo get_theme_file_uri( 'assets/images/kontakt.jpg' ); ?>" alt="" class="rounded contact__img">

    I used all possible combinations of the type:

    <?php echo get_parent_theme_file_uri( ‘assets/images/kontakt.jpg’ ); ?>
    <?php echo get_parent_theme_file_path( ‘assets/images/kontakt.jpg’ ); ?>
    <?php echo get_theme_file_uri( ‘assets/images/kontakt.jpg’ ); ?>
    <?php echo get_theme_file_path( ‘assets/images/kontakt.jpg’ ); ?>

    None of them work.

    The page I need help with: [log in to see the link]

Viewing 15 replies - 1 through 15 (of 20 total)
  • Moderator Steve Stern

    (@sterndata)

    Support Team Volunteer

    Joy

    (@joyously)

    You don’t mention what the folder structure for your theme is, so it’s difficult to determine what the problem is.
    “None of them work.” is not very specific.

    Moderator Steve Stern

    (@sterndata)

    Support Team Volunteer

    Also, the functions don’t put out a trailing / if I recall correctly, so you need to add the slash before assets.

    Also, the functions don’t put out a trailing / if I recall correctly, so you need to add the slash before assets.

    Unfortunately, but it doesn’t work either.

    The only thing that works is to paste the path leading to the uploads folder. But that doesn’t solve the problem either ….

    You don’t mention what the folder structure for your theme is, so it’s difficult to determine what the problem is.
    “None of them work.” is not very specific.

    Please. Look.

    /var/www/html/wordpress/wp-content/themes/WP_Bootstrap/
    ├── assets
    │   ├── css
    │   │   ├── bootstrap.css
    │   │   ├── bootstrap.min.css
    │   │   ├── bootstrap.min.css.map
    │   │   ├── theme.css
    │   │   ├── theme.min.css
    │   │   └── theme.min.css.map
    │   ├── font
    │   │   ├── KelsonSans-Normal.otf
    │   │   ├── KelsonSans-Normal.ttf
    │   │   ├── KelsonSans-Normal.woff
    │   │   └── KelsonSans-Normal.woff2
    │   ├── gfx
    │   │   ├── arrow-blue.png
    │   │   ├── arrow.png
    │   │   ├── gfx-1.png
    │   │   ├── gfx-2.png
    │   │   ├── ico-3.png
    │   │   ├── ico-download.svg
    │   │   ├── icos-social.svg
    │   │   ├── icos.svg
    │   │   ├── ico-szpital-1.svg
    │   │   ├── ico-szpital-2.svg
    │   │   ├___
    │   │ 
    │   ├── images
    │   │   ├── about.jpg
    │   │   ├── baner-1.jpg
    │   │   ├── baner-2.jpg
    │   │   ├── certificates.jpg
    │   │   ├── event.jpg
    │   │   ├── galeria.jpg
    │   │   ├── kontakt.jpg
    │   │   ├── layer-1.jpg
    │   │   ├── logos
    │   │   │   ├── logo-1.png
    │   │   │   ├── logo-2.png
    │   │   │   ├── logo-3.png
    │   │   │   ├── logo-4.png
    │   │   │   ├── logo-5.png
    │   │   │   ├── logo-6.png
    │   │   │   └── logo-7.png
    │   │   ├── medycyna.jpg
    │   │   ├── news.jpg
    │   │   ├── photo-1.jpg
    │   │   ├── photo-2.jpg
    │   │   ├── photo-3.jpg
    │   │   ├── photo-4.1.jpg
    │   │   ├── photo-4.2.jpg
    │   │   ├── photo-4.jpg
    │   │   ├── przychodnia-1.jpg
    │   │   ├── przychodnia-2.jpg
    │   │   ├── przychodnia.jpg
    │   │   ├── szpital.jpg
    │   │   └── what-clinic.png
    │   └── js
    │   ├── bootstrap4
    │   │   ├── bootstrap.bundle.min.js
    │   │   ├── bootstrap.js
    │   │   └── bootstrap.min.js
    │   ├── bootstrap.bundle.js
    │   ├── bootstrap.bundle.min.js
    │   ├── include-html.js
    │   ├── jquery.slim.min.js
    │   ├── slick
    │   │   ├── slick.js
    │   │   └── slick.min.js
    │   ├── theme.js
    │   ├── theme.min.js
    │   └── tmp.js
    ├── class-wp-bootstrap-navwalker.php
    ├── footer.php
    ├── front-page.php
    ├── functions.php
    ├── header.php
    ├── index.php
    ├── page.php
    ├── single.php
    ├── src
    │   └── templates
    │   ├── breadcrumbs.html
    │   ├── footer.html
    │   ├── header.html
    │   ├── need-consultation.html
    │   └── pagination.html
    └── style.css

    • This reply was modified 3 weeks, 4 days ago by nsog8sm43x.
    • This reply was modified 3 weeks, 4 days ago by nsog8sm43x.
    Moderator Steve Stern

    (@sterndata)

    Support Team Volunteer

    When you say “doesn’t work”, what does that mean? What is the resulting URL for the image file?

    When you say “doesn’t work”, what does that mean? What is the resulting URL for the image file?

    404 error in browser…

    Moderator Steve Stern

    (@sterndata)

    Support Team Volunteer

    What is the URL for which you get the error? I understand it’s a 404, but a 404 on what string?

    What is the URL for which you get the error? I understand it’s a 404, but a 404 on what string?

    <img src="<?php echo get_parent_theme_uri( '/assets/images/szpital.jpg' ); ?>” alt=”” class=”rounded”>

    • This reply was modified 3 weeks, 4 days ago by nsog8sm43x.
    Moderator Steve Stern

    (@sterndata)

    Support Team Volunteer

    Please show the ENTIRE <img tag and show your code, too.

    The IMG tag is in one DIV tag.

    <div class="col-md-5 col-xl-4 order-md-2"><img src="<?php echo get_theme_file_uri( 'assets/images/szpital.jpg' ); ?>" alt="" class="rounded"></div>

    Moderator Steve Stern

    (@sterndata)

    Support Team Volunteer

    OK, I’ve asked several times for the output from this. You have not given that answer. One last time… WHAT IS THE RESULT OF YOUR CODE? and PLEASE USE THE FUNCTIONS I SUGGESTED. Sorry to shout.

    Moderator Steve Stern

    (@sterndata)

    Support Team Volunteer

    Your code should be something like

    <img src="<?php echo get_stylesheet_directory_uri();?>/assets/images/szpital.jpg">

    OK, that’s ok. But apparently we don’t understand each other because I wrote back that the result of my code is a 404 error for this image. If you want, I can send you a skewed photo of the image generated by the browser. Code Result? Actually, there is no result, that’s the problem.

    As for your suggestions. I added / before, but the result is the same. Unfortunately, the previous two suggestions are unclear to me.

    Moderator Steve Stern

    (@sterndata)

    Support Team Volunteer

    I have given you the proper code. Please test it.

Viewing 15 replies - 1 through 15 (of 20 total)
  • You must be logged in to reply to this topic.