Where to store all images connected to CSS inside WP

When I see template and WP installation, how to invoke folder assets folder from sites which use CSS and path to assets folder?

I do not like to use media folders as it is defined by developer.
What is the correct path inside CSS to assets folder which contain CSS like

  1. assets/css and link to
  2. assets/images (background). This will not be controlled by user (CMS).

An example inside CSS:

background-image: url("..assets/images/banners1.jpg");

Need help.

Hi toplisek, welcome to the forums! :slightly_smiling_face:

To target a file in the images folders that is in the same directory as the css folder, it should rather be:
background-image: url("../images/banners1.jpg");

The syntax:
A dot means one step up into a parent folder.
A slash means one step down into a named folder.
One dot and a slash before a file name means (up and then back) in the same folder.
Two dots and a slash before a folder name means a folder in the directory above.

Mind that the desired file name should finish the paths above. :slightly_smiling_face:

1 Like

The image parameter is expecting an URL and not a relative path.

I prefer starting at the root and working down:

url(“/assets/images/banners1.jpg”);

1 Like

I understand the path and it is more than less clear.

Will this work to add CSS file from functions.php:

  1. Functions.php
function my_cssscripts_method() {
    wp_enqueue_script(
        'css-custom-script',
        get_stylesheet_directory_uri() . '/assets/styles.css'
    );
}

add_action( 'wp_enqueue_scripts', 'my_cssscripts_method' );

or
2. Direct input:
href=“<?php bloginfo('template_url'); ?>/assets/css/styling.css”
and inside css
url(“/assets/images/banners1.jpg”);
/assets will act as an absolute path in this case like <?php bloginfo('template_url'); ?>

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.