Using hooks
Summary: Hooks in WordPress themes act as key entry points for developers to customize and extend functionality. They allow for dynamic content creation and modifications within the theme. Let’s explore the essential hooks available in our themes for enhanced customization.
🔧 WordPress Theme Hooks in Keystone Themes
Hooks in WordPress themes are essential for extending functionality without modifying core files. While WordPress core provides several hooks, Keystone Themes offers a robust set of custom hooks to help developers insert or modify content at precise locations.
Here’s a breakdown of the essential hooks provided by Keystone Themes:
1. HTML <html>
Hook
keystone_html_before
➤ Inject content before the<html>
tag.
2. HTML <head>
Hooks
keystone_head_top
➤ Insert content at the top of the<head>
section.keystone_head_bottom
➤ Insert content at the bottom of the<head>
section.
3. HTML <body>
Hooks
keystone_body_top
➤ Add content at the beginning of the<body>
tag.keystone_body_bottom
➤ Add content before the closing</body>
tag.
4. Header Hooks
keystone_header_before
keystone_header_after
keystone_header_top
keystone_header_bottom
keystone_header
keystone_page_header_before
keystone_page_header_after
keystone_page_header_top
keystone_page_header_bottom
keystone_page_header_content
➤ Customize the main site header and page headers before/after specific sections.
5. Content Hooks
keystone_content_before
keystone_content_after
keystone_content_top
keystone_content_bottom
keystone_content_primary_top
keystone_content_primary_bottom
keystone_content_while_before
keystone_content_while_after
keystone_content_page
keystone_content_single
keystone_content_loop
keystone_content_404_page
➤ Modify content areas including pages, posts, loops, and 404 pages.
6. Entry Hooks
keystone_entry_before
keystone_entry_after
keystone_entry_content_before
keystone_entry_content_after
keystone_entry_top
keystone_entry_bottom
keystone_entry_wrapper_top
keystone_entry_wrapper_bottom
keystone_entry_content_card
keystone_single_entry_content_top
keystone_single_entry_content_bottom
➤ Target individual entries like blog posts, project items, etc., with fine-grained control.
7. Comments Block Hooks
keystone_comments_before
keystone_comments_after
➤ Inject content before or after the comment section.
8. Sidebar Hooks
keystone_sidebars_before
keystone_sidebars_after
➤ Customize the widget areas and sidebars.
9. Related Posts Block Hooks
keystone_related_content_before
keystone_related_content_after
keystone_related_content_top
keystone_related_content_bottom
➤ Customize how related posts or content blocks appear.
10. Footer Hooks
keystone_footer_before
keystone_footer_after
keystone_footer_top
keystone_footer_bottom
➤ Modify various parts of the footer layout and content.
✅ Pro Tip
To use any of these hooks, just add your custom code like so:
add_action( 'keystone_footer_after', 'custom_footer_message' );
function custom_footer_message() {
echo '<p class="custom-footer-note">Thank you for visiting!</p>';
}
Use these hooks to extend your theme the right way—clean, modular, and update-safe.
Happy coding with Keystone Themes! 🚀