{"id":163,"date":"2013-04-21T14:47:04","date_gmt":"2013-04-21T14:47:04","guid":{"rendered":"http:\/\/musilda.cz\/?p=163"},"modified":"2013-04-21T14:47:04","modified_gmt":"2013-04-21T14:47:04","slug":"pridani-javascriptu-a-externiho-stylu-do-sablony-spravny-zpusob","status":"publish","type":"post","link":"https:\/\/affinite.io\/cs\/pridani-javascriptu-a-externiho-stylu-do-sablony-spravny-zpusob\/","title":{"rendered":"P\u0159id\u00e1n\u00ed javascriptu a extern\u00edho stylu do \u0161ablony – spr\u00e1vn\u00fd zp\u016fsob"},"content":{"rendered":"

Pracujete na nov\u00e9 \u0161ablon\u011b a pot\u0159ebujete do n\u00ed p\u0159idat nap\u0159\u00edklad fancybox? Nen\u00ed nic jednodu\u0161\u0161\u00edho, ne\u017e nahr\u00e1t slo\u017eku do \u0161ablony a pak nalinkovat z head.php pot\u0159ebn\u00e9 soubory. Jak postupn\u011b pracujete webem, p\u0159id\u00e1v\u00e1te nov\u00e9 a nov\u00e9 pluginy, a\u017e zni\u010deho nic, p\u0159estane fancybox fungovat.<\/p>\n

WordPress toti\u017e p\u0159id\u00e1v\u00e1 pot\u0159ebn\u00e9 extern\u00ed styly a js soubory pomoc\u00ed wp_head(), je to doporu\u010den\u00fd zp\u016fsob a p\u0159i v\u00edce pou\u017eit\u00fdch scriptech, jak je u modern\u00edch \u0161ablon b\u011b\u017en\u00e9, jedin\u00fd mo\u017en\u00fd, jak si udr\u017eet kontrolu nad p\u0159\u00edpadn\u00fdmi konflikty. Pro vlo\u017een\u00ed styl\u016f a js scriptu u v\u00fd\u0161e zm\u00edn\u011bn\u00e9ho fancyboxu pou\u017eijeme funkce\u00a0wp_enqueue_style() a\u00a0wp_enqueue_script().<\/p>\n

Do souboru functions.php vlo\u017e\u00edme n\u00e1sleduj\u00edc\u00ed \u0159\u00e1dky:<\/p>\n

function my_eneque() {\n    wp_register_style( 'fancybox', get_template_directory_uri()\n    . '\/fancybox\/jquery.fancybox-1.3.4.css' );\n\n    wp_enqueue_style( 'fancybox' );\n\n    wp_register_script( 'fancybox', get_template_directory_uri()\n    . '\/fancybox\/jquery.fancybox-1.3.4.pack.js', null, null );\n\n    wp_enqueue_script( 'fancybox' );\n\n}\n\nadd_action('wp_enqueue_scripts', 'my_eneque');<\/pre>\n

Do t\u00e9to funkce si m\u016f\u017eeme postupn\u011b vkl\u00e1dat dal\u0161\u00ed soubory a m\u00e1me tak naprost\u00fd p\u0159ehled nad t\u00edm, co do \u0161ablony vkl\u00e1d\u00e1me.
\nPokud chceme m\u00edt jistotu, \u017ee wordpress pou\u017eije jQuery, kter\u00fd chceme, nejprve jej deregistrujeme a pak vlo\u017e\u00edme n\u00e1mi preferovan\u00fd:<\/p>\n

wp_deregister_script( 'jquery' );\nwp_register_script( 'jquery', 'http:\/\/code.jquery.com\/jquery-1.8.0.min.js', null, null);\nwp_enqueue_script( 'jquery' );<\/pre>\n

Edit:<\/span>\u00a0 deregister query po vyzkou\u0161en\u00ed nedoporu\u010duji<\/span>, je lep\u0161\u00ed zavolat jen wp_enqueue_script( ‚jquery‘ );, WordPress pak s\u00e1m vlo\u017e\u00ed knihovnu.<\/p>\n","protected":false},"excerpt":{"rendered":"

Pracujete na nov\u00e9 \u0161ablon\u011b a pot\u0159ebujete do n\u00ed p\u0159idat nap\u0159\u00edklad fancybox? Nen\u00ed nic jednodu\u0161\u0161\u00edho, ne\u017e nahr\u00e1t slo\u017eku do \u0161ablony a pak nalinkovat z head.php pot\u0159ebn\u00e9 soubory. Jak postupn\u011b pracujete webem, p\u0159id\u00e1v\u00e1te nov\u00e9 a nov\u00e9 pluginy, a\u017e zni\u010deho nic, p\u0159estane fancybox fungovat. WordPress toti\u017e p\u0159id\u00e1v\u00e1 pot\u0159ebn\u00e9 extern\u00ed styly a js soubory pomoc\u00ed wp_head(), je to doporu\u010den\u00fd<\/p>\n","protected":false},"author":1,"featured_media":8624,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,19],"tags":[],"class_list":["post-163","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-navody","category-snippety"],"_links":{"self":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/163"}],"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=163"}],"version-history":[{"count":0,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/163\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media\/8624"}],"wp:attachment":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media?parent=163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/categories?post=163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/tags?post=163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}