[resolved] Difficulty including image directory for widget plugin (5 posts)

  1. Sarah_Frantz
    Posted 3 years ago #

    Forgive me if I've posted this question to the wrong forum.

    I want to use a graphic with my widget, but I'm having difficulty including the directory that contains the images specific to the plugin. If someone could point me in the right direction that would be great! The path I want to get to to make the images in the plugin's stylesheet work is:

    my_plugin > assets > images

    So far if I absolutely link to the path of the images they work, but this doesn't help me when I want to package this widget for other installations of WordPress.

    Thank you in advance!

  2. tommcfarlin
    Posted 3 years ago #

    This will depend on if you're looking at retrieve it by its file level path or its URL.

    I typically use the following:

    plugins_url( 'widget-name/assets/images/admin.png' )

    Try that - if it doesn't work, let me know!

  3. Sarah_Frantz
    Posted 3 years ago #

    Hey Tom!

    I'm thinking more so by its file level path. Let me explain a little bit more in-depth the widget I've created and perhaps that might help make sense of which route to take..

    The widget is VERY simple. It is just a textarea where the user can enter in information. The box that is built in the sidebar houses a div with a background image. I'm referencing a stylesheet within the widget plugin to retrieve the styles for this div - however the background images only work if I use the exact path to their location (i.e. the full website url) ... I basically want to make this all "relative" so that I can recycle this plugin on other sites I have, so using the absolute path to the image wont work.

    I'm sure this is more of a file path/structure issue or even a css thing more than anything..

    Have I confused you?

  4. Sarah_Frantz
    Posted 3 years ago #

    OH I'm dumb. haha you're right. Sorry. Thank you!

    Guess I need more coffee...

  5. tommcfarlin
    Posted 3 years ago #

    Don't we all? ;)

Topic Closed

This topic has been closed to new replies.

About this Topic