pre_option_{$option}
最后更新于:2021-11-27 19:32:36
apply_filters( “pre_option_{$option}”, mixed $pre_option, string $option, mixed $default )
Filters the value of an existing option before it is retrieved.
参数
- $pre_option
-
(mixed)
The value to return instead of the option value. This differs from$default
, which is used as the fallback value in the event the option doesn’t exist elsewhere in get_option(). Default false (to skip past the short-circuit). - $option
-
(string)
Option name. - $default
-
(mixed)
The fallback value to return if the option does not exist. Default false.
源文件
文件: gc-includes/option.php
/** * Filters the blogname option on the homepage. * * @param false|mixed $value Pre-option value. Default false. * @param string $option Option name. * @param mixed $default Default option value. * @return false|mixed (Maybe) filtered pre-option value. function gc_docs_pre_filter_option( $pre_option, $option, $default ) { if ( is_home() ) { $pre_option = 'My Awesome Homepage'; } return $pre_option; } add_filter( 'pre_option_blogname', 'gc_docs_pre_filter_option', 10, 3 );
add_filter('pre_option_posts_per_page', 'limit_posts_per_page'); function limit_posts_per_page( $posts_per_page ) { global $gc_query; if ( $gc_query->query_vars['category_name'] == 'foo' ) { return 20; } return $posts_per_page; }