Thursday, 26 December 2013 15:35

how to register scripts and styles in wordpress

Written by 
Rate this item
(0 votes)

In wordpress there are some definite ways to add scripts and styles
in your custom plugin.If you don't follow these rules you might
encounter numerous problems specially related with jquery.

Add this code in your plugin to register scripts and css files for your
custom plugin -

add_action('wp_enqueue_scripts', 'facebook_wall_and_social_integration_scripts');

this action - "wp_enqueue_scripts" is responsible for injecting script and style
files declaration for your plugin.So now you will add above registered function -

function facebook_wall_and_social_integration_scripts() { 
wp_register_script('mitsol_feed_javascript', plugins_url('js/fbookwall.js', __FILE__), array("jquery"));
wp_register_style('mitsol_feed_bootstrap', plugins_url('css/bootstrap.css', __FILE__));

here -

"wp_enqueue_script" will register jquery first if you needed.
"wp_register_script" will register custom javascript file inside your plugin, in
this case you have to add "wp_enqueue_script" as function shows.

Likewise, you add styles by the last two lines in the above function.

Hope you liked it.if you have further questions, then post in discussions forum.

Read 2712 times Last modified on Saturday, 17 August 2019 07:56
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.

Latest discussions

  • No posts to display.