1. do_action, add_action, remove_action, & add_filter
do_action()
– where the “hooked” functions are runadd_action()
– attaches a function to a hook as defined by do_actionremove_action()
– removes a function attached to a specified action hook
So the do_action functions are already added to the theme and will run whenever something is hooked into them via add_action. So you, as the user, will be using the add_action and remove_action functions only to make your modifications.
2. AIOS Starter Theme
List of custom hook
-
action_name: aios_starter_theme_before_inner_page_content
funciton_name|priority: action_name_action | 11
filter|args|priority: action_name_filter | $content | 10
existing_filter: aios_starter_theme_add_breadcrumbs -
action_name: aios_starter_theme_before_entry
funciton_name|priority: action_name_action | 11
filter|args|priority: action_name_filter | $content | 10
existing_filter: ai_starter_theme_add_post_meta -
action_name: aios_starter_theme_after_entry_content
funciton_name|priority: action_name_action | 11
filter|args|priority: action_name_filter | $content | 10
existing_filter: ai_starter_theme_add_comments_section
3. How to use hook?
On the example above we will use add_action
and add_filter
to achieve the same result.
Add extra text using add_action:
We will add text below the default content of inner page content after the breadcrumb.
add_action( 'aios_starter_theme_before_inner_page_content', 'add_text_on_action', 13 );
function add_text_on_action() {
echo 'This is test for additional content under breadcrumb';
}
We will add text above the default content of before end of inner page content.
add_action( 'aios_starter_theme_after_entry_content', 'add_text_on_action_bottom', 11 );
function add_text_on_action_bottom() {
echo 'This is test for additional content before end of content';
}
Add extra text using add_filter:
add_filter( 'aios_starter_theme_before_inner_page_content_filter', 'add_text_on_action', 11 );
function add_text_on_action( $content ) {
return $content . 'This is test for additional content under breadcrumb';
}
add_filter( 'aios_starter_theme_after_entry_content_filter', 'add_text_on_action_bottom', 11 );
function add_text_on_action_bottom( $content ) {
return 'This is test for additional content before end of content' . $content;
}
4. Removing an Action & Filter
We hook into “init” so that it runs after the theme has a chance to add it’s own actions. The hook uses class instance: $aios_starter_theme_hook_action
Action
add_action( 'init', 'remove_parent_theme_actions' );
function remove_parent_theme_actions() {
global $aios_starter_theme_hook_action;
remove_action( 'aios_starter_theme_before_inner_page_content', array( $aios_starter_theme_hook_action, 'aios_starter_theme_before_inner_page_content_action' ), 11 );
remove_action( 'aios_starter_theme_before_entry', array( $aios_starter_theme_hook_action, 'aios_starter_theme_before_entry_action' ), 11 );
remove_action( 'aios_starter_theme_after_entry_content', array( $aios_starter_theme_hook_action, 'aios_starter_theme_after_entry_content_action' ), 11 );
}
Filter
add_action( 'init', 'remove_parent_theme_actions' );
function remove_parent_theme_actions() {
global $aios_starter_theme_hook_action;
remove_filter( 'aios_starter_theme_before_inner_page_content_filter', array( $aios_starter_theme_hook_action, 'aios_starter_theme_add_breadcrumbs' ) );
}