{"id":1134,"date":"2013-09-20T05:47:56","date_gmt":"2013-09-20T05:47:56","guid":{"rendered":"http:\/\/musilda.cz\/?p=1134"},"modified":"2013-09-20T05:47:56","modified_gmt":"2013-09-20T05:47:56","slug":"funkce-wp_enqueue_script","status":"publish","type":"post","link":"https:\/\/affinite.io\/cs\/funkce-wp_enqueue_script\/","title":{"rendered":"Funkce wp_enqueue_script"},"content":{"rendered":"

Funkce wp_enqueue_script vytv\u00e1\u0159\u00ed odkaz na script, kter\u00fd jste ji\u017e d\u0159\u00edve zaregistrovali pomoc\u00ed wp_register_script. Jedn\u00e1 se o jedin\u00fd spr\u00e1vn\u00fd zp\u016fsob, jak vkl\u00e1dat do \u0161ablony nap\u0159\u00edklad jQuery, proto\u017ee WordPress kontroluje zaregistrovan\u00e9 scripty a nedoch\u00e1z\u00ed tak k opakovan\u00e9mu na\u010dten\u00ed stejn\u00e9ho scriptu.<\/p>\n

\nwp_enqueue_script( $handle, $src, $deps, $ver, $in_footer );\n<\/pre>\n

Parametry:<\/h2>\n

$handle – vy\u017eadov\u00e1no, obsahuje jm\u00e9no scriptu, pod kter\u00fdm je zaregistrov\u00e1n. Pokud jste tedy zaregistrovali script pod jm\u00e9nem „slider“, pod stejn\u00fdm jm\u00e9nem ho budete volat v t\u00e9to funkci.<\/p>\n

$src – cesta ke scriptu. Povinn\u00e1 je pouze v tom p\u0159\u00edpad\u011b, \u017ee jste ji ji\u017e nedefinovali v wp_register_script. V \u017e\u00e1dn\u00e9m p\u0159\u00edpad\u011b v cest\u011b nepou\u017e\u00edvejte pevn\u00e9 pojmenov\u00e1n\u00ed url, ale v p\u0159\u00edpad\u011b pluginu funkci plugins_url a v \u0161ablon\u011b get_template_directory_uri.<\/p>\n

$deps – pomoc\u00ed tohoto parametru m\u016f\u017eete ovlivnit \u0159azen\u00ed vkl\u00e1dan\u00fdch script\u016f a ur\u010dit, kter\u00fd soubor se vkl\u00e1d\u00e1 d\u0159\u00edve. Pou\u017eijte pouze, pokud jste jej nedefinovali v wp_register_sript.<\/p>\n

$ver – zde m\u016f\u017eete definovat verzi scriptu a defaultn\u011b je nastavena na false. V tom p\u0159\u00edpad\u011b WordPress automaticky p\u0159id\u00e1v\u00e1 do url verzi instalace WordPressu. Pokud chcete link bez uveden\u00ed verze, nastavte na null.<\/p>\n

$in_footer – ur\u010duje, zda se bude script na\u010d\u00edtat v head, nebo footer. Pokud je true, na\u010dte se v pati\u010dce. Defaultn\u011b je false.<\/p>\n

N\u011bkolik p\u0159\u00edklad\u016f z WordPress.org<\/h2>\n

Proto\u017ee jsem na toto t\u00e9ma ji\u017e \u010dl\u00e1nek napsal – Jak vlo\u017eit javascript do \u0161ablony<\/a>, uvedu jen p\u0159\u00edklady, kter\u00e9 \u010dl\u00e1nek roz\u0161i\u0159uj\u00ed.<\/p>\n

Vlo\u017een\u00ed js souboru, kter\u00fd je ji\u017e ve WordPressu vlo\u017een a zaregistrov\u00e1n:<\/strong><\/p>\n

\nfunction my_scripts_method() {\n    wp_enqueue_script( 'scriptaculous' );\n}\n\nadd_action( 'wp_enqueue_scripts', 'my_scripts_method' );\n<\/pre>\n

Akce wp_enqueue, kterou zde vol\u00e1me, se vztahuje jen k frontendu. Pokud pot\u0159ebujeme soubory vlo\u017eit do administrace, mus\u00edme pou\u017e\u00edt hook admin_enqueue_scripts.<\/p>\n

Vlo\u017een\u00ed scriptu v z\u00e1vislosti na jQuery<\/strong><\/p>\n

\u0158ada vkl\u00e1dan\u00fdch script\u016f je z\u00e1visl\u00e1 na n\u011bkter\u00e9 z knihoven, jako je jQuery. Pokud pou\u017eijeme parametr $deps, vlo\u017e\u00ed se script pouze, pokud ji\u017e bylo vlo\u017eeno jQuery.<\/p>\n

\nfunction my_scripts_method() {\n\twp_enqueue_script(\n\t\t'custom-script',\n\t\tget_stylesheet_directory_uri() . '\/js\/custom_script.js',\n\t\tarray( 'jquery' )\n\t);\n}\n\nadd_action( 'wp_enqueue_scripts', 'my_scripts_method' );\n<\/pre>\n

Vlo\u017een\u00ed scriptu do pati\u010dky bez z\u00e1vislosti na jin\u00e9m souboru<\/strong><\/p>\n

\nadd_action( 'wp_enqueue_scripts', 'child_add_scripts' );\n\nfunction child_add_scripts() {\n    wp_register_script(\n        'google-analytics',\n        get_stylesheet_directory_uri() . '\/google_analytics_object.js',\n        false,\n        '1.0',\n        true\n    );\n\n    wp_enqueue_script( 'google-analytics' );\n}\n<\/pre>\n

Scripty, kter\u00e9 WordPress ji\u017e obsahuje a vkl\u00e1d\u00e1:<\/h2>\n

P\u0159i instalaci ji\u017e WordPress obsahuje \u0159adu script\u016f, kter\u00e9 vyu\u017e\u00edv\u00e1 v administraci a pro funkce webu. Zde je seznam v\u0161ech script\u016f, kter\u00e9 tak m\u016f\u017eete pou\u017e\u00edt ve sv\u00fdch \u0161ablon\u00e1ch a pluginech:<\/p>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
Jm\u00e9no<\/td>\nHandle<\/td>\nZ\u00e1vislost<\/td>\n<\/tr>\n
Image Cropper<\/td>\nImage cropper<\/td>\n<\/td>\n<\/tr>\n
Jcrop<\/td>\njcrop<\/td>\n<\/td>\n<\/tr>\n
SWFObject<\/td>\nswfobject<\/td>\n<\/td>\n<\/tr>\n
SWFUpload<\/td>\nswfupload<\/td>\n<\/td>\n<\/tr>\n
SWFUpload Degrade<\/td>\nswfupload-degrade<\/td>\n<\/td>\n<\/tr>\n
SWFUpload Queue<\/td>\nswfupload-queue<\/td>\n<\/td>\n<\/tr>\n
SWFUploadHandlers<\/td>\nswfupload-handlers<\/td>\n<\/td>\n<\/tr>\n
jQuery<\/td>\njquery<\/td>\njson2 (for AJAX calls)<\/td>\n<\/tr>\n
jQuery Form<\/td>\njquery-form<\/td>\njquery<\/td>\n<\/tr>\n
jQuery Color<\/td>\njquery-color<\/td>\njquery<\/td>\n<\/tr>\n
jQuery Masonry<\/td>\njquery-masonry<\/td>\njquery<\/td>\n<\/tr>\n
jQuery UI Core<\/td>\njquery-ui-core<\/td>\njquery<\/td>\n<\/tr>\n
jQuery UI Widget<\/td>\njquery-ui-widget<\/td>\njquery<\/td>\n<\/tr>\n
jQuery UI Mouse<\/td>\njquery-ui-mouse<\/td>\njquery<\/td>\n<\/tr>\n
jQuery UI Accordion<\/td>\njquery-ui-accordion<\/td>\njquery<\/td>\n<\/tr>\n
jQuery UI Autocomplete<\/td>\njquery-ui-autocomplete<\/td>\njquery<\/td>\n<\/tr>\n
jQuery UI Slider<\/td>\njquery-ui-slider<\/td>\njquery<\/td>\n<\/tr>\n
jQuery UI Tabs<\/td>\njquery-ui-tabs<\/td>\njquery<\/td>\n<\/tr>\n
jQuery UI Sortable<\/td>\njquery-ui-sortable<\/td>\njquery<\/td>\n<\/tr>\n
jQuery UI Draggable<\/td>\njquery-ui-draggable<\/td>\njquery<\/td>\n<\/tr>\n
jQuery UI Droppable<\/td>\njquery-ui-droppable<\/td>\njquery<\/td>\n<\/tr>\n
jQuery UI Selectable<\/td>\njquery-ui-selectable<\/td>\njquery<\/td>\n<\/tr>\n
jQuery UI Position<\/td>\njquery-ui-position<\/td>\njquery<\/td>\n<\/tr>\n
jQuery UI Datepicker<\/td>\njquery-ui-datepicker<\/td>\njquery<\/td>\n<\/tr>\n
jQuery UI Resizable<\/td>\njquery-ui-resizable<\/td>\njquery<\/td>\n<\/tr>\n
jQuery UI Dialog<\/td>\njquery-ui-dialog<\/td>\njquery<\/td>\n<\/tr>\n
jQuery UI Button<\/td>\njquery-ui-button<\/td>\njquery<\/td>\n<\/tr>\n
jQuery UI Effects<\/td>\njquery-effects-core<\/td>\njquery<\/td>\n<\/tr>\n
jQuery UI Effects – Blind<\/td>\njquery-effects-blind<\/td>\njquery-effects-core<\/td>\n<\/tr>\n
jQuery UI Effects – Bounce<\/td>\njquery-effects-bounce<\/td>\njquery-effects-core<\/td>\n<\/tr>\n
jQuery UI Effects – Clip<\/td>\njquery-effects-clip<\/td>\njquery-effects-core<\/td>\n<\/tr>\n
jQuery UI Effects – Drop<\/td>\njquery-effects-drop<\/td>\njquery-effects-core<\/td>\n<\/tr>\n
jQuery UI Effects – Explode<\/td>\njquery-effects-explode<\/td>\njquery-effects-core<\/td>\n<\/tr>\n
jQuery UI Effects – Fade<\/td>\njquery-effects-fade<\/td>\njquery-effects-core<\/td>\n<\/tr>\n
jQuery UI Effects – Fold<\/td>\njquery-effects-fold<\/td>\njquery-effects-core<\/td>\n<\/tr>\n
jQuery UI Effects – Highlight<\/td>\njquery-effects-highlight<\/td>\njquery-effects-core<\/td>\n<\/tr>\n
jQuery UI Effects – Pulsate<\/td>\njquery-effects-pulsate<\/td>\njquery-effects-core<\/td>\n<\/tr>\n
jQuery UI Effects – Scale<\/td>\njquery-effects-scale<\/td>\njquery-effects-core<\/td>\n<\/tr>\n
jQuery UI Effects – Shake<\/td>\njquery-effects-shake<\/td>\njquery-effects-core<\/td>\n<\/tr>\n
jQuery UI Effects – Slide<\/td>\njquery-effects-slide<\/td>\njquery-effects-core<\/td>\n<\/tr>\n
jQuery UI Effects – Transfer<\/td>\njquery-effects-transfer<\/td>\njquery-effects-core<\/td>\n<\/tr>\n
MediaElement.js (WP 3.6+)<\/td>\nwp-mediaelement<\/td>\njquery<\/td>\n<\/tr>\n
jQuery Schedule<\/td>\nschedule<\/td>\njquery<\/td>\n<\/tr>\n
jQuery Suggest<\/td>\nsuggest<\/td>\njquery<\/td>\n<\/tr>\n
ThickBox (modified)<\/td>\nthickbox<\/td>\n<\/td>\n<\/tr>\n
jQuery HoverIntent<\/td>\nhoverIntent<\/td>\njquery<\/td>\n<\/tr>\n
jQuery Hotkeys<\/td>\njquery-hotkeys<\/td>\njquery<\/td>\n<\/tr>\n
Simple AJAX Code-Kit<\/td>\nsack<\/td>\n<\/td>\n<\/tr>\n
QuickTags<\/td>\nquicktags<\/td>\n<\/td>\n<\/tr>\n
Iris (Colour picker)<\/td>\niris<\/td>\njquery<\/td>\n<\/tr>\n
Farbtastic (deprecated)<\/td>\nfarbtastic<\/td>\njquery<\/p>\n
ColorPicker (deprecated)<\/td>\ncolorpicker<\/td>\njquery<\/td>\n<\/tr>\n
Tiny MCE<\/td>\ntiny_mce<\/td>\n<\/td>\n<\/tr>\n
Autosave<\/td>\nautosave<\/td>\n<\/td>\n<\/tr>\n
WordPress AJAX Response<\/td>\nwp-ajax-response<\/td>\n<\/td>\n<\/tr>\n
List Manipulation<\/td>\nwp-lists<\/td>\n<\/td>\n<\/tr>\n
WP Common<\/td>\ncommon<\/td>\n<\/td>\n<\/tr>\n
WP Editor<\/td>\neditorremov<\/td>\n<\/td>\n<\/tr>\n
WP Editor Functions<\/td>\neditor-functions<\/td>\n<\/td>\n<\/tr>\n
AJAX Cat<\/td>\najaxcat<\/td>\n<\/td>\n<\/tr>\n
Admin Categories<\/td>\nadmin-categories<\/td>\n<\/td>\n<\/tr>\n
Admin Tags<\/td>\nadmin-tags<\/td>\n<\/td>\n<\/tr>\n
Admin custom fields<\/td>\nadmin-custom-fields<\/td>\n<\/td>\n<\/tr>\n
Password Strength Meter<\/td>\npassword-strength-meter<\/td>\n<\/td>\n<\/tr>\n
Admin Comments<\/td>\nadmin-comments<\/td>\n<\/td>\n<\/tr>\n
Admin Users<\/td>\nadmin-users<\/td>\n<\/td>\n<\/tr>\n
Admin Forms<\/td>\nadmin-forms<\/td>\n<\/td>\n<\/tr>\n
XFN<\/td>\nxfn<\/td>\n<\/td>\n<\/tr>\n
Upload<\/td>\nupload<\/td>\n<\/td>\n<\/tr>\n
PostBox<\/td>\npostbox<\/td>\n<\/td>\n<\/tr>\n
Slug<\/td>\nslug<\/td>\n<\/td>\n<\/tr>\n
Post<\/td>\npost<\/td>\n<\/td>\n<\/tr>\n
Page<\/td>\npage<\/td>\n<\/td>\n<\/tr>\n
Link<\/td>\nlink<\/td>\n<\/td>\n<\/tr>\n
Comment<\/td>\ncomment<\/td>\n<\/td>\n<\/tr>\n
Threaded Comments<\/td>\ncomment-reply<\/td>\n<\/td>\n<\/tr>\n
Admin Gallery<\/td>\nadmin-gallery<\/td>\n<\/td>\n<\/tr>\n
Media Upload<\/td>\nmedia-upload<\/td>\n<\/td>\n<\/tr>\n
Admin widgets<\/td>\nadmin-widgets<\/td>\n<\/td>\n<\/tr>\n
Word Count<\/td>\nword-count<\/td>\n<\/td>\n<\/tr>\n
Theme Preview<\/td>\ntheme-preview<\/td>\n<\/td>\n<\/tr>\n
JSON for JS<\/td>\njson2<\/td>\n<\/td>\n<\/tr>\n
Plupload Core<\/td>\nplupload<\/td>\n<\/td>\n<\/tr>\n
Plupload All Runtimes<\/td>\nplupload-all<\/td>\n<\/td>\n<\/tr>\n
Plupload HTML4<\/td>\nplupload-html4<\/td>\n<\/td>\n<\/tr>\n
Plupload HTML5<\/td>\nplupload-html5<\/td>\n<\/td>\n<\/tr>\n
Plupload Flash<\/td>\nplupload-flash<\/td>\n<\/td>\n<\/tr>\n
Plupload Silverlight<\/td>\nplupload-silverlight<\/td>\n<\/td>\n<\/tr>\n
Underscore js<\/td>\nunderscore<\/td>\n<\/td>\n<\/tr>\n
Backbone js<\/td>\nbackbone<\/td>\n<\/td>\n<\/tr>\n<\/table>\n

Vyu\u017eit\u00ed takov\u00fdch script\u016f v\u00e1m ur\u010dit\u011b usnadn\u00ed pr\u00e1ci na \u0161ablon\u00e1ch a m\u016f\u017eete vyu\u017e\u00edvat \u0159adu funkc\u00ed, kter\u00e9 ji\u017e WordPress v z\u00e1kladu m\u00e1.<\/p>\n","protected":false},"excerpt":{"rendered":"

Funkce wp_enqueue_script vytv\u00e1\u0159\u00ed odkaz na script, kter\u00fd jste ji\u017e d\u0159\u00edve zaregistrovali pomoc\u00ed wp_register_script. Jedn\u00e1 se o jedin\u00fd spr\u00e1vn\u00fd zp\u016fsob, jak vkl\u00e1dat do \u0161ablony nap\u0159\u00edklad jQuery, proto\u017ee WordPress kontroluje zaregistrovan\u00e9 scripty a nedoch\u00e1z\u00ed tak k opakovan\u00e9mu na\u010dten\u00ed stejn\u00e9ho scriptu.<\/p>\n","protected":false},"author":1,"featured_media":8523,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[7,22],"tags":[161],"class_list":["post-1134","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-codex","category-template-tags","tag-funkce-wp_enqueue_script"],"_links":{"self":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/1134"}],"collection":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/comments?post=1134"}],"version-history":[{"count":0,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/1134\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media\/8523"}],"wp:attachment":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media?parent=1134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/categories?post=1134"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/tags?post=1134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}