• Hi – I’m a WP newb and learning to build my first child theme site installed locally using MAMP. I can build a flat html/css site in my sleep but WP requires me to be fully awake and caffeinated.

    I was reading the Function Reference about using get_stylesheet_directory_uri which I want to use so that I can more easily load images from my child theme’s images directory.
    Copying/pasting & personalizing the example in the Reference I enter this onto the Edit screen of the page –

    <img src=”<?php echo get_stylesheet_directory_uri(); ?>/images/trial-image.png”
    alt=”trial” width=”” height=”” />

    …and hit the Update button. This has been unsuccessful enough times that I tried every variation of the path until I realized that Updating the page caused the syntax of the PHP code to change “?>” to “?/>”.

    Is that correct syntax? Is that common behavior?

    I don’t know how to proceed. It seems that either the Function Reference is incorrect or WP is trying to tell me something totally mysterious. Either way no images are appearing on my page.

    Thanks in advance for your help.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi, you can’t add/edit PHP in the post editor in WordPress. It will get changed and filtered out. This is for security reasons. You need to add PHP code to your theme template files instead.

    Thread Starter n0ty0u

    (@n0ty0u)

    mindctrl – thanks for the response. OK. I think I have to go back to “lesson one” again. There is something I missed about images in Child themes.

    It makes sense that Posts shouldn’t contain PHP but – and I don’t know if this makes a difference in your response or not – this site won’t have Posts or any blogging functions. I’m using WP to build a fully responsive website that I can turn over to someone else to maintain. I was working on one of those static Pages when this confusion with “where the images came from” came up.

    I thought the images that I specifically added and used in my child site pages would be separate and isolated from the parent theme. So that updating the parent wouldn’t effect the new images. That’s why I wanted to change the path from the image directory of the parent to the image directory of the child. Is that so or am I stuck in my pre-WP ways?

    I appreciate any guidance you can provide. Even if its a link back to the first grade.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Updating page changes get_styleshet_directory syntax’ is closed to new replies.