• Hi,

    I have developed a child theme for public release. The theme directory has its own image folder (images) which contain images like pic.png, pic1.jpg and so.

    Now in the theme, while designing pages I used relative URLs on images pointing to the image directory like

    /wp-content/themes/theme-name/images/pic.png

    Now it works fine when someone installs the theme on his/her site https://www.example.com. The image URLs become

    https://www.example.com/wp-content/themes/theme-name/images/pic.png

    Now the issue is the sub-directory, like https://www.example.com/sub-folder sites. Then they install the theme, the image URLs become

    https://www.example.com/wp-content/themes/theme-name/images/pic.png

    But the actual path must be like

    https://www.example.com/sub-folder/wp-content/themes/theme-name/images/pic.png

    So, all the image links are broken and return 404. Any solution to this.

    Thanks

Viewing 1 replies (of 1 total)
  • You can use the WP function get_stylesheet_directory_uri() to solve the problem.

    The slick way is to only call it once (saving overhead) for each script:

    $image_path = get_stylesheet_directory_uri();

    Then, for each image, you can just echo it there:

    <img src="<?php echo $image_path; ?>/images/pic.png" ... />

    Or, you can just call the function each place you need it:

    <img src="<?php echo get_stylesheet_directory_uri(); ?>/images/pic.png" ... />

Viewing 1 replies (of 1 total)
  • The topic ‘Relative URLs on a Sub-directory’ is closed to new replies.