![]() At this point, your stylesheet and your javascript will load everywhere on the front end of the site. 'script.js', array( 'jquery' ), $this->version, true ) Īs you can see, your function cssjs() waits for bp_enqueue_scripts before using the two WordPress functions to load your style ( wp_enqueue_style()) and your script ( wp_enqueue_script()). Wp_enqueue_script( 'buddyplug-js', $this->plugin_js. Your script file is reachable at site.url/wp-content/plugins/buddyplug/includes/js/script.js 'buddyplug.css', false, $this->version ) Wp_enqueue_style( 'buddyplug-css', $this->plugin_css. Your css file is reachable at site.url/wp-content/plugins/buddyplug/includes/css/buddyplug.css As soon as WordPress meets this hook, your cssjs function will be calledĪdd_action( 'bp_enqueue_scripts', array( $this, 'cssjs' ) ) $this->plugin_css = trailingslashit( $this->includes_url. url to your plugin's css dir : site.url/wp-content/plugins/buddyplug/includes/css/ $this->plugin_js = trailingslashit( $this->includes_url. url to your plugin's js dir : site.url/wp-content/plugins/buddyplug/includes/js/ $this->includes_url = trailingslashit( $this->plugin_url. url to your plugin's includes dir : site.url/wp-content/plugins/buddyplug/includes/ $this->plugin_url = plugin_dir_url( $this->file ) url to your plugin dir : site.url/wp-content/plugins/buddyplug/ let's define some globals to easily build the url to your scripts #WORDPRESS ENQUEUE SCRIPT ON SPECIFIC PAGE HOW TO#The first one is bp_enqueue_scripts for enqueueing your script on the front end, here’s an example on how to use it from your plugin’s class: Allow the theme to override your stylesheetĬhoose the best hook to enqueue your scriptsĭepending on the context, BuddyPress offers two hooks to rely on in order to safely load your scripts.Choose the best hook to enqueue your scripts.It comes with a BuddyPress plugin “boilerplate” (BuddyPlug) that you will find in the additional resources and will help you to achieve this “roadmap”: Steps To illustrate an usage example, you can test the following tutorial. allow the theme to override your CSS rules.enqueue your Javascript or CSS only when your plugin needs it,.your CSS rules might not get along with the activated theme.you might not be the only one to use Javascript, other plugins can be activated in the community website,.I think, as a plugin author, you need to have two concerns : Using Javascipt or CSS in BuddyPress plugins are interesting ways to take care of the user experience. Codex Home → BuddyPress Plugin Development → Enqueueing Scripts or Styles only when your plugin needs itĮnqueueing Scripts or Styles only when your plugin needs it ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |