Support » Fixing WordPress » Simple question on short code function

  • Resolved BunnyBomb


    Hello there,

    I need a teeny bit of help here. I expect it will take 2 seconds for someone who knows php to tell me the answer, but I’ve failed after a good effort to Google it.

    I have created a short code to generate a unique sidebar, to be used in various places in my website. I want full control over this bit of html in posts/pages, so putting the code into a template didn’t work for me.

    Here is the code:

    You’ll notice I have used the full path to the background images being used. For example, the first one is written like this:

    I would prefer to use the get_stylesheet_directory_uri() function to call the first part of the link, but I don’t know how to do this within my code.

    I have read the codex, but unfortunately it is written from the perspective of inserting php into html. I’m inserting php, into html, into php (can’t believe I just typed that) and I’m not experienced enough to know how to do this 🙁

    I’d really appreciate if someone could give me the write context for this.

Viewing 3 replies - 1 through 3 (of 3 total)
  • To be clear, the above code is working fine. Beautifully, in fact.

    I just don’t like the context of the links, so want to improve them to be relative to my theme folder. I have done that using get_stylesheet_directory_uri() in my template files, but I don’t know how to do it inside a function.

    This is basic php stuff, so I’m sure someone will know…



    Forum Moderator

    for example, change the existing sections from:
    <img src="./wp-content/themes/catrescue/images/wee_cat_4.png" width="40" height="40" />

    <img src="' . get_stylesheet_directory_uri() . '/images/wee_cat_4.png" width="40" height="40" />

    see php string concatenation

    Thank you so much, that worked perfectly.

    I was so close with my trial attempts. Was using the . to connect the statements like above, but I didn’t have it quite right.

    Thanks again 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Simple question on short code function’ is closed to new replies.