Home > OS >  Why is index.php showing up in my image link paths?
Why is index.php showing up in my image link paths?

Time:10-22

I'm building a theme using a local server(xampp). I have created a setting through the customizer where someone can select from a number of backgrounds I created using a dropdown list. Everything was working fine in the live preview and on the static home page. As soon as I created a new page, I got a 404 error, and this path for the image: http://localhost:777/wordpress-5.8/wordpress**/index.php/front-page/**wp-content/themes/sophia-valeria/backgrounds/bgg33.jpg

That link is not going to work. I'm not sure why this is happening.

I do note that every time I create a page, it has index.php in the URL, but the home page does not.

My css looks like this:

function understanding_bg(){                  ?>
         <style>
    body{ background-repeat:no-repeat;
    background-size:100% 100%;
    background-image: url(<?php echo(get_theme_mod('backgrounds_setting', get_stylesheet_directory() . '/backgrounds/bgg33.jpg'));?>);}
     </style> <?php }
    add_action( 'wp_head', 'understanding_bg'); 

I don't know whether this is a weird apache thing or what—any ideas on what I have to do to make the images not incorporate page titles and index.php. I am missing something here.

CodePudding user response:

Try this way

function understanding_bg(){                  ?>
         <style>
    body{ background-repeat:no-repeat;
    background-size:100% 100%;
    background-image: url("<?php echo get_stylesheet_directory() . '/backgrounds/bgg33.jpg';?>");}
     </style> <?php }
    add_action( 'wp_head', 'understanding_bg'); 

Or directly place the whole path for the background image.

background-image: url("/wp-content/themes/yourThemeName/backgrounds/bgg33.jpg");

If the above one is not working, try this one.

  • Related