WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Child theme referencing child files (11 posts)

  1. janmalagucute
    Member
    Posted 2 years ago #

    Hi,

    I am reading this article
    http://codex.wordpress.org/Child_Themes

    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?

    Thanks

  2. esmi
    Forum Moderator
    Posted 2 years ago #

    That code is to include a file - not images.

  3. janmalagucute
    Member
    Posted 2 years ago #

    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

  4. esmi
    Forum Moderator
    Posted 2 years ago #

    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.

  5. janmalagucute
    Member
    Posted 2 years ago #

    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.

  6. esmi
    Forum Moderator
    Posted 2 years ago #

    Are these images being referenced in your child's stylesheet, template files or within your Posts/Pages?

  7. janmalagucute
    Member
    Posted 2 years ago #

    stylesheet and template files

  8. esmi
    Forum Moderator
    Posted 2 years ago #

    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" />

  9. janmalagucute
    Member
    Posted 2 years ago #

    ahh... there it is.. ok.. thanks.. now I got it.

    Thanks a lot.

  10. Santosh
    Member
    Posted 1 year ago #

    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

  11. esmi
    Forum Moderator
    Posted 1 year ago #

    Please post your own topic.

Topic Closed

This topic has been closed to new replies.

About this Topic