Support » Themes and Templates » [Resolved] Child theme referencing child files

[Resolved] Child theme referencing child files

  • janmalagucute



    I am reading this article

    Down the line, I notice this part and I think this is what I am missing on my child theme.

    require_once( get_stylesheet_directory(). '/my_included_file.php' );

    In normal cases, where should that code be added so that I can reference image files on my child theme?

    If I added that, can I still reference files in mother theme and files in child theme?


Viewing 10 replies - 1 through 10 (of 10 total)
  • That code is to include a file – not images.




    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?


    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..


    if I am using the mother theme, that will load

    If I want to load

    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?


    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:


    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.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘[Resolved] Child theme referencing child files’ is closed to new replies.
Skip to toolbar