Photo by 900hp
One of the most powerful under-the-hood features of WordPress (and the Genesis framework) is the ability to override almost any option or meta value: site options, post meta, user meta, term meta, and more. Using filters to intercept these values gives you flexible control over how themes and plugins behave on specific pages or contexts.
A word of caution: be careful when using these filters. Themes and plugins expect certain values from core functions, and returning unexpected values in the wrong context can break functionality. Only return modified values in the specific instances where you intend to change behavior.
Common use cases for overriding options and meta include:
- Change the admin email on certain pages (site option).
- Change the default layout of the homepage (Genesis site option).
- Force a layout on the homepage (post meta).
- Enable the Genesis author box automatically for author archives (user meta).
- Provide a default headline for term archives (term meta).
Site Options
Site options are stored in the wp_options table and are typically accessed via get_option(). WordPress exposes a filter that allows you to override those values: pre_option_($key). You can use that filter to change an option’s returned value conditionally.
Example 1: Change the admin email on single posts
Suppose you add an “Email Us” link to the footer that uses the admin_email option, but on single post pages you want that link to use the post author’s email instead. You could implement it like this:
Email Us';
}
add_action( 'wp_footer', 'be_email_us' );
function be_post_author_email( $email ) {
global $post;
if ( is_single() && isset( $post->post_author ) ) {
$email = get_the_author_meta( 'user_email', $post->post_author );
}
return $email;
}
add_filter( 'pre_option_admin_email', 'be_post_author_email' );
This shows how to intercept a site option and return a different value only on single post pages.
Example 2: Change the default layout on the homepage (Genesis)
Genesis stores many settings as a serialized array. To override Genesis options the framework provides genesis_pre_get_option_($key). For example, to set the homepage default layout to full-width, you can hook into that filter:
Place this code in front-page.php or home.php — whichever template renders your homepage — or in functions.php if you check the request context before returning the override.
Post Meta
WordPress provides get_post_metadata (get_post_meta wrapper/filter) to allow modification of post meta values when they are retrieved. This can be used to force a specific layout for a page by overriding the _genesis_layout post meta.
Example 3: Force a layout on the front page
If you want to prevent the layout from being changed by the user on the front page, intercept the meta request for _genesis_layout and return the desired layout:
If you want this to apply only to the page set as the front page in Settings > Reading, check the post ID:
Because the filter provides the $post_id, you can place this in functions.php and still target a specific page.
User Meta
To modify author/user meta values at runtime, use the get_the_author_($key) family of filters. This lets you override author meta returned by get_the_author_meta() and similar functions.
Example 4: Automatically enable the Genesis author box for archive pages
Genesis stores author box preferences in user meta keys like genesis_author_box_archive. To always show the author box on author archive pages, you can force that value to true using a built-in helper:
Note: __return_true() is a WordPress core helper function that simply returns true.
Term Meta
WordPress historically did not include term meta; some frameworks (like Genesis) emulate term meta using the options table and expose a filter genesis_term_meta_($key) to modify those values.
Example 5: Provide a default headline for a taxonomy term archive
On a photography site you might have a taxonomy “people” and want term archive pages to display a headline like “Photos of [Person Name]” if no headline is set. Use the Genesis term meta filter to return a sensible default:
name;
}
add_filter( 'genesis_term_meta_headline', 'be_person_intro', 10, 2 );
Relevant Filters and Helper Functions
Useful filters you can hook into:
- WP: pre_option_($key)
- WP: get_the_author_($key)
- WP: get_post_metadata
- Genesis: genesis_pre_get_option_($key)
- Genesis: genesis_term_meta_($key)
Handy helper functions:
- WordPress: __return_true() — returns true.
- WordPress: __return_false() — returns false.
- WordPress: __return_zero() — returns 0.
- WordPress: __return_empty_array() — returns an empty array.
- WordPress: __return_null() — returns null.
- Genesis: __genesis_return_full_width_content() — returns ‘full-width-content’.
- Genesis: __genesis_return_content_sidebar() — returns ‘content-sidebar’.
- Genesis: other __genesis_return_* helpers for built-in layout slugs.
Use these filters to alter returned options and meta values only where necessary, and always confirm your conditionals so theme and plugin behavior remains predictable. Place context-specific code in the appropriate template (front-page.php, home.php) or in functions.php with proper checks for the request context.