Skip to content
Simon Padbury edited this page Nov 5, 2018 · 2 revisions

b4st has a system of theme hooks, into which a child theme (or a plugin) can add or override some actions.

The 8 empty hooks are located in pairs:

  • Before and after the site #navbar
  • Before and after the site #main
  • Before and after the site #sidebar
  • Before and after the site #footer

(#sidebar is within #main, and it will only be displayed if there is at least one widget in the sidebar widget area.)

In addition to the empty hooks there are 3 overridable hooks that are used for building:

  • The navbar .brand
  • The navbar search form
  • The “bottomline” (i.e. site copyright notice and b4st theme notice, below the #footer)

You will find all these theme hooks in https://github.com/SimonPadbury/b4st/blob/master/functions/hooks.php

In a child theme, you can add stuff into the 8 empty hooks and/or override stuff in the 3 pluggable hooks by creating functions that hook into:

navbar_before
navbar_brand
navbar_search
navbar_after
	
main_before	
sidebar_before
sidebar_after
main_after
	
footer_before
footer_after
bottomline

You can do amazing things with these hooks. Following are a few examples:

Example: adding a special notice above the navbar

function special_notice() {
	?>
	<div style="background:red;color:white;text-align:center">
		This is a special notice . . .
	</div>
	<?php
}
add_action( 'navbar_before', 'special_notice' );

Observe how this child theme function simply:

  • breaks out of PHP with ?> in order to add some HTML
  • goes back into PHP with <?php in order to complete the function with }, and then
  • add_action is used to hook this function into the b4st (parent) theme at the location of navbar_before

Example: removing the navbar search form

function remove_navbar_search() {
	// Leave empty
}
add_action( 'navbar_search', 'remove_navbar_search' );

Simply adding an empty function to an overridable hook will override the content of that hook with nothing i.e. it will actually remove the content.

Example: replacement for the bottomline

function replace_bottomline() {
	?>
	This is my own bottomline . . .
	<?php
}
add_action( 'bottomline', ‘replace_bottomline' );

That’s how you can swap out the default bottomline for something you want.