wp-lemon Docs

Filters & Actions

Filters & Actions

Hooks are a way for one piece of code to interact/modify another piece of code at specific, pre-defined spots. You can 'hook' into them to modify a set piece of code. Hooks come in the form of actions and filters.

Actions

Actions allow you to add data or change how WordPress operates. Actions will run at a specific point in the execution of WordPress Core, plugins, and themes. Callback functions for Actions can perform some kind of a task, like echoing output to the user or inserting something into the database. Callback functions for an Action do not return anything back to the calling Action hook.

We use actions in wp-lemon throughout the twig files to add new data on specific spots without overwriting the complete twig file. This means you can upgrade your child themes more easily in the future.

Filters

Filters give you the ability to change data during the execution of WordPress Core, plugins, and themes. Callback functions for Filters will accept a variable, modify it, and return it. They are meant to work in an isolated manner, and should never have side effects such as affecting global variables and output. Filters expect to have something returned back to them.

We use filters in wp-lemon to change specific output that is already baked into the templates. It serves the same purpose as actions are used on a smaller scale, like changing an icon inside a card for example.

Actions inside blocks

Hooks are in the correct order.

Action hookDescription
wp-lemon/action/block/{{slug}}/beforeAdd elements inside a block, before the actual block
wp-lemon/action/block/{{slug}}/afterAdd elements inside a block, after the actual block
wp-lemon/action/block/node-overview/{{card_type}}/loop/beforeAdd elements before the loop
wp-lemon/action/block/node-overview/{{card_type}}/loop/afterAdd elements after the loop

Actions inside wp-lemon core files

Hooks are in the correct order.

Action hookDescription
wp-lemon/action/head/metaInsert extra meta information inside the head element. Use this hook to add extra tracking scripts for example.
wp-lemon/action/body/beforeInsert code inside the body opening tag before all other child elements
wp-lemon/action/header/beforeInsert code directly before the the header/navbar
wp-lemon/action/navbar/beforeInsert code directly inside the the header/navbar
wp-lemon/action/menu-toggle/beforeInsert code directly before the menu toggler
wp-lemon/action/menu-toggle/afterInsert code directly after the menu toggler
wp-lemon/action/main-menu/beforeInsert code directly before the nav menu inside the navbar
wp-lemon/action/main-menu/afterInsert code directly after the nav menu inside the navbar
wp-lemon/action/navbar/afterInsert code directly inside & before the end of the the header/navbar
wp-lemon/action/header/afterInsert code directly after the the header/navbar
wp-lemon/action/content/beforeInsert code inside the .main opening tag before all other child elements
wp-lemon/action/entry/beforeInsert code inside the .entry opening tag before all other child elements
wp-lemon/action/entry/content/beforeInsert code inside the .entry opening tag before all other child elements but after wp-lemon/action/entry/before
wp-lemon/action/entry-header/{{post_type}}/title/beforeInsert code before the title in the entry header
wp-lemon/action/entry-header/{{post_type}}/title/afterInsert code after the title in the entry header
wp-lemon/action/entry-header/{{post_type}}/tags/afterInsert code after the tags in the entry header
wp-lemon/action/entry-header/{{post_type}}/picture/afterInsert code after the picture in the entry header
wp-lemon/action/entry-footer/beforeInsert code before the the entry-after.twig file
wp-lemon/action/entry/content/afterInsert code inside the .entry opening tag before all other child elements but before wp-lemon/action/after
wp-lemon/action/entry/afterInsert code just before the closing .entry tag
wp-lemon/action/content/afterInsert code inside the .main opening tag after all other child elements
wp-lemon/action/footer/beforeInsert code before footer
wp-lemon/action/footer/inside/beforeInsert code inside the footer as the first element.
wp-lemon/action/footer-widgets/afterInsert code after footer widgets area
wp-lemon/action/footer-widgets/inside/beforeInsert code before and inside footer widgets area
wp-lemon/action/footer-widgets/beforeInsert code before actual widgets
wp-lemon/action/footer-widgets/afterInsert code after actual widgets
wp-lemon/action/footer-widgets/inside/afterInsert code after and inside footer widgets area
wp-lemon/action/footer/inside/afterInsert code inside the footer as the last element.
wp-lemon/action/footer/afterInsert code after footer
wp-lemon/action/body/afterInsert code inside the body opening tag after all other child elements
wp-lemon/action/floating-buttons/beforeAdd additional floating items in the contact-buttons div before the other buttons
wp-lemon/action/floating-buttons/afterAdd additional floating items in the contact-buttons div after the other buttons
wp-lemon/action/cookiebar/text/beforeAdd text before the default text in the cookiebar
wp-lemon/action/cookiebar/text/afterAdd text after the default text in the cookiebar

Examples

library/hooks.php
1namespace WP_Lemon\Child\Controllers;
2
3use Timber\Timber;
4use function HighGround\Bulldozer\helpers\asset;
5
6/**
7 * Add static contact bar on every page.
8 *
9 * @return void
10 */
11function add_contact_bar()
12{
13 $context = Timber::get_context();
14 $context['classes'] = array('acf-block', 'contact-bar', 'alignfull', 'has-background', 'has-blue-background-color', 'has-text-color', 'has-black-color');
15
16 Timber::render('blocks/contact-bar.twig', $context);
17}
18
19add_action('wp-lemon/action/content/after', __NAMESPACE__ . '\\add_contact_bar');
20
21/**
22 * Insert logo's of certificates directly after the footer widgets.
23 *
24 * @return void
25 */
26function footer_logos()
27{
28 $context = Timber::get_context();
29 $context['footer_logos'] = [
30 asset('images/logos/ebn-9001.svg')->uri(),
31 asset('images/logos/veritas-f-gassen.svg')->uri(),
32 asset('images/logos/techniek-nederland.svg')->uri(),
33 asset('images/logos/veritas-brl-6000.svg')->uri(),
34 asset('images/logos/ebn-vca.svg')->uri(),
35 ];
36
37 Timber::render('partials/footer-logos.twig', $context);
38}
39
40add_action('wp-lemon/action/footer-widgets/after', __NAMESPACE__ . '\\footer_logos');

Filters available inside regular PHP files.

Filter hookDescription
wp-lemon/filter/javascript-translations-pathSet translation path of javascript translations. return get_stylesheet_directory() . '/resources/languages/'
wp-lemon/filter/socials-orderChange the default order of the socials in blocks, headers and footers.
wp-lemon/filter/blocksFilters the blocks loaded by the parent theme.
wp-lemon/filter/core-blocks-to-removeRemove or add blocks that we want to unregister
wp-lemon/filter/navwalker/{{item_archive}}/link-attributesAdd extra arguments to item archive blocks.
wp-lemon/filter/share-contextFilter the share array. You can change the name, icon and share url or add/remove share platforms
wp-lemon/filter/socials-contextFilter the socials array to be shown
wp-lemon/filter/single/templatesFilter the template array, has the post type as second parameter
wp-lemon/filter/translations/frontendFilter the frontend translations. You can add your own translations here.
wp-lemon/filter/phone-number/resultChanges the result of a phone number from the transient or after generation
wp-lemon/filter/phone-number/default-formatSet the default format for phone numbers to transform to. Can be national, international, combined and localized
wp-lemon/filter/language-switcherFilters the language switcher. By using this filter you can change the output of the language switcher.
wp-lemon/filter/special-pagesFilters the special pages. When you add a key, value combination to this array, the page will show up in the customizer under special pages where you can set the page. After that it will also be added in the context under the pages key.
wp-lemon/filter/a11y/skip-linksAllow child theme to add or remove skip links.
wp-lemon/filter/webp-qualityFilter the quality of the webp image.

Filters available inside models

Filter hookDescription
wp-lemon/filter/model/acf-fields/jobFilter/extend the job fields
wp-lemon/filter/model/acf-fields/personFilter/extend the person fields
wp-lemon/filter/model/acf-fields/menuFilter/extend the menu fields

Filters available PHP block declarations

Filter hookDescription
wp-lemon/filter/block/image-sizesFilters the image sizes inside all blocks that use image_sizes context variable
wp-lemon/filter/block/{{block_name}}/image-sizesFilters the image sizes inside all blocks that use image_sizes context variable for a specific block.
wp-lemon/filter/block/{{block_name}}/allowed-blocksFilter allowed blocks
wp-lemon/filter/block/{{block_name}}/{{dynamic_post_type}}/image-sizesFilters the image sizes inside all blocks that use image_sizes context variable for a specific block and a specific variant
wp-lemon/filter/block/node-latest/{{dynamic_post_type}}/no-items-messageUsed in the node-latest block to change the message when no items are found that is shown to the site visitors.
wp-lemon/filter/block/node-latest/{{dynamic_post_type}}/overview-button-textUsed in the node-latest block to change the text in the button leading to the overview page of that post type
wp-lemon/filter/block/node-latest/{{dynamic_post_type}}/argsFilter the query args for the latest items query
wp-lemon/filter/block/node-latest/{{card_type}}/holder-classesFilter the holder classes
wp-lemon/filter/block/node-overview/{{dynamic_post_type}}/load-more-textChange load more text.
wp-lemon/filter/block/node-overview/{{card_type}}/holder-classesFilter the holder classes
wp-lemon/filter/block/node-overview/{{card_type}}/itemsFilter the post array
wp-lemon/filter/block/node-overview/{{card_type}}/posts-per-pageFilter the amount of posts to be loaded via Ajax
wp-lemon/filter/block/node-overview/{{dynamic_post_type}}/select-all-textUsed in the node-overview block to change the text of the first option in the select element.
wp-lemon/filter/block/node-overview/{{dynamic_post_type}}/argsFilter the query args for the node overview query

Filters available Twig files

Filter hookDescriptionarguments
wp-lemon/filter/header/renderRender the header, use __return_false to disable the header.
wp-lemon/filter/header/breakpointSet the breakpoint on which the menu collapses. Can be xs,sm, md, lg,xl, xxl. Use it in combination with $menu-breakpoints: ( xs: 0, menu: 992px);
wp-lemon/filter/header/logoChange output of the logo inside the header , has logo array as argument.
wp-lemon/filter/card/iconChange the arrow icon inside a cards footer.
wp-lemon/filter/card/excerpt-lengthChange the excerpt length inside cards
wp-lemon/filter/card/{{card_type}}/excerpt-lengthChange the excerpt length inside a specific cards
wp-lemon/filter/card/{{card_type}}/animationChange default animation of a card.
wp-lemon/filter/card/{{card_type}}/image-idFilters the image id inside a card.
wp-lemon/filter/card/{{card_type}}/picture-classesFilter the picture classes inside a card
wp-lemon/filter/card/{{card_type}}/picture-elfilter the whole picture element inside cards
wp-lemon/filter/card/{{card_type}}/footerfilter the card footer
wp-lemon/filter/card/person/phonenumberFilter the phone number that is displayed a person card.
wp-lemon/filter/entry-header/image-sizeUsed to change the image size of the image in the entry-header.twig
wp-lemon/filter/entry-header/{{post_type}}/tagsUsed to change the tags section in the entry-header.twig of a specific post type. Or set to false to remove it completely.
wp-lemon/filter/entry-header/{{post_type}}/typeUsed to change the post type text above the title in the entry-header.twig of a specific post type. Or set to false to remove it completely.
wp-lemon/filter/entry-header/{{post_type}}/dateUsed to change the date text in the entry-header.twig of a specific post type. Or set to false to remove it completely.
wp-lemon/filter/entry-header/{{post_type}}/titleUsed to change the title in the entry-header.twig of a specific post type. Or set to false to remove it completely.
wp-lemon/filter/entry-header/{{post_type}}/picture-elFilters the complete picture element.(mixed) image id
wp-lemon/filter/entry-header/{{post_type}}/image-sizeUsed to change the image size of the image in the entry-header.twig of a specific post type.
wp-lemon/filter/entry-header/{{post_type}}/image-idUsed to change the image id of the image in the entry-header.twig of a specific post type. Or set to false to remove it completely.
wp-lemon/filter/entry-header/{{post_type}}/archive-pageFilter the archive page array(array) nav
wp-lemon/filter/entry-footer/share-buttons/showWhether to show the share buttons
wp-lemon/filter/entry-footer/share-buttons/platformsremove or change the order of the share platforms
wp-lemon/filter/entry-footer/share-buttons/hide-labelsWhether or not to hide the labels
wp-lemon/filter/entry-footer/{{post_type}}/share-buttons/showremove or change the order of the share platforms
wp-lemon/filter/entry-footer/{{post_type}}/share-buttons/post-type-nameChange share heading label
wp-lemon/filter/entry-footer/{{post_type}}/share-buttons/platformsFilter the platform array to add/remove share platforms
wp-lemon/filter/entry-footer/{{post_type}}/share-buttons/titleFilter the title in front of the buttons
wp-lemon/filter/footer/renderRender the footer, use __return_false to disable the footer.
wp-lemon/filter/footer/show-logoWhether to show the footer logo
wp-lemon/filter/footer/show-bottombarWhether to show the bottom bar holding to copyright message etc
wp-lemon/filter/copyright-messageReturns the copyright message, use this to change the copyright message in the
wp-lemon/filter/date-notationSet the date notation in search results and cards.
wp-lemon/filter/cookiebar/show-analytics-checkboxbool, whether to show the analytics checkbox
wp-lemon/filter/cookiebar/show-marketing-checkboxbool, whether to show the marketing checkbox
wp-lemon/filter/cookiebar/textstring, modify the default cookiebar text
wp-lemon/filter/cookiebar/functionalstring, modify functional cookie checkbox label
wp-lemon/filter/cookiebar/analyticsstring, modify analytics cookie checkbox label
wp-lemon/filter/cookiebar/marketingstring, modify marketing cookie checkbox label
wp-lemon/filter/cookiebar/rejectstring, modify reject button text
wp-lemon/filter/cookiebar/acceptstring, modify accept button text

Examples

library/controllers/filters.php
1namespace WP_Lemon\Child\Controllers;
2
3
4add_filter('wp-lemon/filter/card/icon', function () {
5 return 'icon-chevron-right';
6});
7
8add_filter("wp-lemon/filter/node-overview/news/image-sizes", function ($sizes) {
9 return '(min-width: 768px) 700px,
10 (min-width: 600px) 510px,
11 400px';
12});
13
14
15add_filter('wp-lemon/filter/card/news/picture-el', function ($el, $post_id) {
16 return get_field('oembed', $post_id);
17}, 10, 2);
Edit this page on GitHub