{"id":4227,"date":"2022-08-22T00:38:21","date_gmt":"2022-08-21T19:08:21","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-clarification-on-filters-and-hooks\/"},"modified":"2022-08-22T00:38:21","modified_gmt":"2022-08-21T19:08:21","slug":"solved-clarification-on-filters-and-hooks","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-clarification-on-filters-and-hooks\/","title":{"rendered":"[Solved] Clarification on filters and hooks"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-103644\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"103644\" data-parentid=\"103641\" data-score=\"7\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<blockquote>\n<p>I am confused because add_filter uses the word add when I feel like it<br \/>\n  is more on the lines of replace or overwrite (unless I am<br \/>\n  misunderstanding)<\/p>\n<\/blockquote>\n<p>You are misunderstanding. Both <code>add_action<\/code> and <code>add_filter<\/code> insert function callbacks into a kind of queue. You can add many callbacks to the same hook and they will fire in the sequence added except when a priority is included as the third parameter.<\/p>\n<blockquote>\n<p>So in this situation is the apply_filter just creating a dynamic<br \/>\n  method on the fly and making it return the chicken string?<\/p>\n<\/blockquote>\n<p><code>apply_filters<\/code> &#8212; note the &#8216;s&#8217;&#8211; does more or less create the filter but usually it is passed a variable not a string and that variable is passed to the callback which then alters it and returns it.<\/p>\n<p>Filter &#8216;slugs&#8217; are not the names of WordPress Core functions or methods as a rule though some functions have filters of the same name. For example, <code>the_content()<\/code> calls the <code>the_content<\/code> filter. <\/p>\n<p>Hooks do not usually override whole function, only parts of them, but there are exceptions and near exceptions.<\/p>\n<blockquote>\n<p>Also, can you only apply_filter something that you&#8217;ve add_filtered ?<\/p>\n<\/blockquote>\n<p>No. The other way around. You can only <code>add_filter<\/code> something that is <code>apply_filter<\/code>ed. You can use <code>add_filter('whatever','abc');<\/code> but nothing at all will happen if there is not an <code>apply_filter('whatever',...<\/code> somewhere.<\/p>\n<p>Pretty much the same applies to <code>add_action<\/code>\/<code>do_action<\/code> but actions are for doing things rather than returning values.<\/p>\n<p>Hooks are executed at various times in the page load and at various places in functions and methods. For example, <code>save_post<\/code> executes near the end of <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/core.trac.wordpress.org\/browser\/tags\/3.5.1\/wp-includes\/post.php#L2950\"><code>wp_insert_post<\/code><\/a> while <code>pre_get_posts<\/code> executes near the top of the <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/core.trac.wordpress.org\/browser\/tags\/3.5.1\/wp-includes\/query.php#L1924\"><code>get_posts<\/code><\/a> method of the <code>WP_Query<\/code> class. Others execute in <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/core.trac.wordpress.org\/browser\/tags\/3.5.1\/wp-admin\/edit-form-advanced.php#L147\">the middle of the page load<\/a> and not in a function or method at all. They execute where ever there is a need (as determined by the developers) to either alter or add information, or run other functions, redirect a page, etc.<\/p>\n<h1>More Information<\/h1>\n<p>Difference Between Filter and Action Hooks?<\/p>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">2<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved Clarification on filters and hooks <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] I am confused because add_filter uses the word add when I feel like it is more on the lines of replace or overwrite (unless I am misunderstanding) You are misunderstanding. Both add_action and add_filter insert function callbacks into a kind of queue. You can add many callbacks to the same hook and they will &#8230; <a title=\"[Solved] Clarification on filters and hooks\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-clarification-on-filters-and-hooks\/\" aria-label=\"More on [Solved] Clarification on filters and hooks\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[627],"tags":[706,705,690],"class_list":["post-4227","post","type-post","status-publish","format-standard","hentry","category-wordpress","tag-core","tag-filters","tag-hooks"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] Clarification on filters and hooks - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-clarification-on-filters-and-hooks\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] Clarification on filters and hooks - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] I am confused because add_filter uses the word add when I feel like it is more on the lines of replace or overwrite (unless I am misunderstanding) You are misunderstanding. Both add_action and add_filter insert function callbacks into a kind of queue. You can add many callbacks to the same hook and they will ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-clarification-on-filters-and-hooks\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-21T19:08:21+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-clarification-on-filters-and-hooks\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-clarification-on-filters-and-hooks\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] Clarification on filters and hooks\",\"datePublished\":\"2022-08-21T19:08:21+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-clarification-on-filters-and-hooks\/\"},\"wordCount\":333,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"core\",\"filters\",\"hooks\"],\"articleSection\":[\"WordPress\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-clarification-on-filters-and-hooks\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-clarification-on-filters-and-hooks\/\",\"name\":\"[Solved] Clarification on filters and hooks - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-08-21T19:08:21+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-clarification-on-filters-and-hooks\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-clarification-on-filters-and-hooks\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-clarification-on-filters-and-hooks\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] Clarification on filters and hooks\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775193939\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775193939\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] Clarification on filters and hooks - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-clarification-on-filters-and-hooks\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] Clarification on filters and hooks - JassWeb","og_description":"[ad_1] I am confused because add_filter uses the word add when I feel like it is more on the lines of replace or overwrite (unless I am misunderstanding) You are misunderstanding. Both add_action and add_filter insert function callbacks into a kind of queue. You can add many callbacks to the same hook and they will ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-clarification-on-filters-and-hooks\/","og_site_name":"JassWeb","article_published_time":"2022-08-21T19:08:21+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-clarification-on-filters-and-hooks\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-clarification-on-filters-and-hooks\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] Clarification on filters and hooks","datePublished":"2022-08-21T19:08:21+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-clarification-on-filters-and-hooks\/"},"wordCount":333,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["core","filters","hooks"],"articleSection":["WordPress"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-clarification-on-filters-and-hooks\/","url":"https:\/\/jassweb.com\/solved\/solved-clarification-on-filters-and-hooks\/","name":"[Solved] Clarification on filters and hooks - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-08-21T19:08:21+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-clarification-on-filters-and-hooks\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-clarification-on-filters-and-hooks\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-clarification-on-filters-and-hooks\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] Clarification on filters and hooks"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775193939","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775193939","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/4227","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=4227"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/4227\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=4227"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=4227"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=4227"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}