WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Simple question on short code function (4 posts)

  1. BunnyBomb
    Member
    Posted 2 years ago #

    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: http://pastebin.com/aejbVaYA

    You'll notice I have used the full path to the background images being used. For example, the first one is written like this:
    .wp-content/themes/catrescue/images/image

    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.

  2. BunnyBomb
    Member
    Posted 2 years ago #

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

  3. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

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

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

    see php string concatenation
    http://php.net/manual/en/language.operators.string.php

  4. BunnyBomb
    Member
    Posted 2 years ago #

    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 :)

Topic Closed

This topic has been closed to new replies.

About this Topic