Home>Support>register_frontend_styles to footer

register_frontend_styles to footer

Hi!
Im making my own modules to page builder.
It is possible to load CSS in footer like JS files?

Im trying to find this in plugin sorce code, but I can’t found.
It is possible to set globaly for all widgets?

function initialize()
    {
	    $this->register_frontend_scripts(
		    array(
			    array(
			    	$this->so_plugin_slug,
				    $this->so_plugin_url . 'tpl/script.js',
				    array('jquery'),
				    self::SO_PLUGIN_VER,
                                    true // add to fotter
			    ),
		    )
	    );

	    $this->register_frontend_styles(
		    array(
			    array($this->so_plugin_slug, $this->so_plugin_url . 'tpl/main.min.css', array(), self::SO_PLUGIN_VER),
		    )
	    );
    }

This is our free support forum. Replies can take several days. If you need fast email support, please purchase a SiteOrigin Premium license.

  1. 13 days, 8 hours ago Alex Stapleton Hi, I Work Here

    Hi,

    register_frontend_styles is a helper function for wp_enqueue_style. This function doesn’t work in the same way as wp_enqueue_script so it’s not possible to tell WordPress to output the script to the footer when registering them.

    You could override enqueue_frontend_scripts and hook into wp_footer and output your CSS there. You’ll need to do this for each widget however as this method – and related styling – is widget specific.

    Kind regards,
    Alex

  2. 13 days, 4 hours ago fpweb

    hmm something like this in my widget?

    function enqueue_frontend_scripts( $instance ) {
    		$this->enqueue_registered_scripts( $instance );
    		add_action('get_footer',  $this->enqueue_registered_styles( $instance));
    
    		do_action('siteorigin_widgets_enqueue_frontend_scripts_' . $this->id_base, $instance, $this);
    }
    
  3. 13 days, 4 hours ago Alex Stapleton Hi, I Work Here

    Hi Fpweb,

    I recommend using wp_footer instead of get_footer. You add a hook for get_footer and then use $this->enqueue_registered_styles( $instance).

    Kind regards,
    Alex

Please log in to post on our forums. Signing up is free.

Get The Most Out of SiteOrigin with SiteOrigin Premium

Find Out More