Support » Fixing WordPress » How are assets managed by a wordpress html widget

  • Resolved akshatjiwan



    Recently wordpress added a custom html widget to the core. I was experimenting with it and it seems that I can even add <script> and <link> tags to it and it renders perfectly. My goal is to create a widget that loads some external libraries and renders an html form that is dynamically created. There will be two libraries

    1. A font awesome css file
    2. My custom javascript file served from a cdn

    My question is how does the widget handle the <script> and <link> tags. Can I reuse the assets loaded by the widget elsewhere in my wordpress. I understand that I can en queue this script but I’d prefer to use the widgets because I find them really convenient. Do you think it is a good idea for what I’m trying to achieve?


Viewing 2 replies - 1 through 2 (of 2 total)
  • This is really not what widgets are for. Unless the stylesheet and script are only for the HTML added to the widget, then the stylesheet and script don’t belong there. If you have stylesheets and scripts that are used for the widget and other things on your site, then they should be enqueued properly.

    Many thanks Jacob for the reply! I have a followup. Lets say that I want to use a single html widget with assets in multiple places. On my sidebar, in my footer etc. In that case are the assets downloaded multiple times? I understand that en queuing the scripts and links is the best course of action but there is another use-case that I might need to handle. Should I still be en-queuing?


Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How are assets managed by a wordpress html widget’ is closed to new replies.