That code is to include a file – not images.
Hi,
Thanks for your reply. I know that code will include a file so that I can reference my images stored inside my child theme folder instead of the images inside the mother theme folder.
What I do not know is Which file should I edit to add that code?
header.php, index.php, etc… which file and what line specifically?
Thanks
so that I can reference my images stored inside my child theme folder
You shouldn’t have to do anything to reference your child’s images.
Sorry. Perhaps I am not using the right words.
let say I want to display image01.jpg this code..
images/image01.jpg
if I am using the mother theme, that will load
mother-theme/images/image01.jpg
If I want to load
child-theme/images/image01.jpg
according to the article i posted on my original question I need to use
require_once( get_stylesheet_directory(). '/my_included_file.php' );
to be able to reference my files inside the child theme.
Here’s the exact words in the article…
Referencing / Including Files in Your Child Theme
When you need to include files that reside within your child theme’s directory structure, you will use get_stylesheet_directory(). Because the parent template’s style.css is replaced by your child theme’s style.css, and your style.css resides in the root of your child theme’s subdirectory, get_stylesheet_directory() points to your child theme’s directory (not the parent theme’s directory).
Here’s an example, using require_once, that shows how you can use get_stylesheet_directory when referencing a file stored within your child theme’s directory structure.
require_once( get_stylesheet_directory(). '/my_included_file.php' );
now my question is how can I use that code?
Which file should I edit?
Thanks.
and sorry if I am writing it poorly. Im not a native english speaker.
Are these images being referenced in your child’s stylesheet, template files or within your Posts/Pages?
stylesheet and template files
In the stylesheet, you should be able to reference them using something like:
background:url(images/my-image.jpg)
as normal. In the template files, use:
<img src="<?php echo get_stylesheet_directory();?>/images/my-image.jpg" width="xxx" height="yyy" alt="Text alternative" />
ahh… there it is.. ok.. thanks.. now I got it.
Thanks a lot.
I am also having same problem here is my code for child theme style sheet
span a {
background: url(<?php echo get_stylesheet_directory();?>/images/sprites-buttons.gif) no-repeat 0 -303px;
color: #fdfdfb;
display: inline-block;
font-family: ‘CarterOneRegular’;
font-size: 16px;
height: 38px;
line-height: 37px;
margin-left: 10px;
text-align: center;
text-decoration: none;
text-shadow: 1px 1px 0 #216b20;
width: 136px;
}
this is not working for me please help me
Please post your own topic.