PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

How to add style sheet when using widget?

  1. I am trying to use the yoast widget to show a form, but it does not load the styles or scripts. So I added a shortcode filter to functions.php and put a shortcode,
    gravityform id=1 name=ContactUs ajax=true]
    In a text widget, ajax works, but styles do not load. Any way to solve this?
    Thanks!

    Posted 13 years ago on Thursday April 14, 2011 | Permalink
  2. Try using the built-in Gravity Forms widget instead and you shouldn't have a problem. Or if you want to stick with the Yoast widget, here's how you would do it.

    When using a Gravity Form in a sidebar widget or embedding it anywhere using the function call, you need to manually enqueue the scripts and CSS by placing a short script block in your theme's functions.php file.

    if(!is_admin()) {
        wp_enqueue_script("gforms_ui_datepicker", WP_PLUGIN_URL . "/gravityforms/js/jquery-ui/ui.datepicker.js", array("jquery"), "1.4", true);
        wp_enqueue_script("gforms_datepicker", WP_PLUGIN_URL . "/gravityforms/js/datepicker.js", array("gforms_ui_datepicker"), "1.4", true);
        wp_enqueue_script("gforms_conditional_logic_lib", WP_PLUGIN_URL . "/gravityforms/js/conditional_logic.js", array("gforms_ui_datepicker"), "1.4", true);
        wp_enqueue_style("gforms_css", WP_PLUGIN_URL . "/gravityforms/css/forms.css");
    }

    Without this, the conditional logic scripts, datepicker script, form CSS and other elements needed for the full form functionality aren't loaded.

    You can find more information at the URL below

    http://www.gravityhelp.com/documentation/page/Embedding_A_Form

    Posted 13 years ago on Thursday April 14, 2011 | Permalink
  3. Right thanks. I will do that in the future, was just using the widget for a temporary form and didn't want to alter my theme files. No biggie.
    Thanks. :)

    Posted 13 years ago on Thursday April 14, 2011 | Permalink