{"id":6618,"date":"2022-02-03T08:46:40","date_gmt":"2022-02-03T08:46:40","guid":{"rendered":"https:\/\/musilda.cz\/?p=6618"},"modified":"2022-02-03T08:46:40","modified_gmt":"2022-02-03T08:46:40","slug":"poradi-hooku-pri-nacteni-wordpress-stranky","status":"publish","type":"post","link":"https:\/\/affinite.io\/cs\/poradi-hooku-pri-nacteni-wordpress-stranky\/","title":{"rendered":"Po\u0159ad\u00ed hook\u016f p\u0159i na\u010dten\u00ed WordPress str\u00e1nky"},"content":{"rendered":"\n
Zn\u00e1te to. Pot\u0159ebujete n\u011bco upravit a na Stack Overflow jste sice na\u0161li funkci, nebo popis \u0159e\u0161en\u00ed, ale kam ji sakra d\u00e1t? <\/p>\n\n\n\n
Dej to do functions.php – zn\u00ed nejb\u011b\u017en\u011bj\u0161\u00ed rada. Tak tam tu funkci d\u00e1te a nic se nestane. Jak to?<\/p>\n\n\n\n
Je to proto, \u017ee soubor functions.php se na\u010d\u00edt\u00e1 hned po na\u010dten\u00ed plugin\u016f a m\u016f\u017ee se st\u00e1t, \u017ee to co chcete upravovat se definuje pozd\u011bji.<\/p>\n\n\n\n
\u0158ekn\u011bme, \u017ee chceme v k\u00f3du functions.php pracovat s taxonomi\u00ed WooCommerce, nap\u0159\u00edklad product_cat. <\/p>\n\n\n\n
Bohu\u017eel se n\u00e1m nepoda\u0159\u00ed k\u00f3d prov\u00e9st, proto\u017ee register_taxonomies ve WooCommerce, se prov\u00e1d\u00ed a\u017e v init hooku, tedy po na\u010dten\u00ed functions.php. Tak\u017ee v tu chv\u00edli \u017e\u00e1dn\u00e1 product_cat nen\u00ed definovan\u00e1. <\/p>\n\n\n\n
\u0158e\u0161en\u00edm je vytvo\u0159it funkci, kterou d\u00e1me do functions.php a pomoc\u00ed hooku, \u0159ekneme WordPressu, kdy chceme, aby funkci provedl. <\/p>\n\n\n\n
Logicky se nab\u00edz\u00ed init, kde se registruje WooCommerce taxonomie. Pozor v\u0161ak dejte na to, \u017ee register_taxonomy m\u00e1 pozici 5, tak\u017ee vy mus\u00edte m\u00edt pozici 6 a v\u00edce, aby se va\u0161e funkce provedla a\u017e kdy\u017e m\u00e1te taxonomii definovanou. <\/p>\n\n\n\n
P\u0159i na\u010dten\u00ed ka\u017ed\u00e9 str\u00e1nky ve WordPressu, se hooky se\u0159ad\u00ed do po\u0159ad\u00ed v jak\u00e9m budou prov\u00e1d\u011bny. Na ka\u017ed\u00e9 str\u00e1nce se to m\u016f\u017ee trochu li\u0161it, ale z\u00e1klad je v\u017edy stejn\u00fd. N\u00e1sleduj\u00edc\u00ed seznam ukazuje po\u0159ad\u00ed hooku WordPressu (proto\u017ee do nich jsou je\u0161t\u011b vkl\u00edn\u011bny hooky \u0161ablony a plugin\u016f), na\u010dten\u00fdch na homepage, definovan\u00e9 jako statick\u00e1 str\u00e1nka.<\/p>\n\n\n\n
Tak\u017ee, takto vypad\u00e1 sekvence na\u010d\u00edt\u00e1n\u00ed v\u0161ech akc\u00ed p\u0159i na\u010dten\u00ed WordPressu. <\/p>\n\n\n\n
A aby jste m\u011bli p\u0159edstavu, co se sekvenc\u00ed ud\u011blaj\u00ed \u0161ablony a pluginy, na odkazu najdete sekvenci na\u010d\u00edt\u00e1n\u00ed, kdy\u017e je nainstalovan\u00e1 \u0161ablona Astra, WooCommerce, Elementor a n\u011bkolik z\u00e1kladn\u00edch plugin\u016f – https:\/\/musilda.cz\/wp-content\/wp_load_sequention_elementor.html<\/a><\/p>\n\n\n\n Douf\u00e1m, \u017ee alespo\u0148 n\u011bkomu tento \u010dl\u00e1nek pom\u016f\u017ee pochopit, jak jsou hooky se\u0159azeny za sebou a pro\u010d mu nefunguje \u00faprava, kterou ud\u011blal.<\/p>\n","protected":false},"excerpt":{"rendered":" Zn\u00e1te to. Pot\u0159ebujete n\u011bco upravit a na Stack Overflow jste sice na\u0161li funkci, nebo popis \u0159e\u0161en\u00ed, ale kam ji sakra d\u00e1t? Dej to do functions.php – zn\u00ed nejb\u011b\u017en\u011bj\u0161\u00ed rada. Tak tam tu funkci d\u00e1te a nic se nestane. Jak to? Je to proto, \u017ee soubor functions.php se na\u010d\u00edt\u00e1 hned po na\u010dten\u00ed plugin\u016f a m\u016f\u017ee se<\/p>\n","protected":false},"author":1,"featured_media":8624,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30],"tags":[],"class_list":["post-6618","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress"],"_links":{"self":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/6618"}],"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=6618"}],"version-history":[{"count":0,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/6618\/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=6618"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/categories?post=6618"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/tags?post=6618"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}