admin管理员组文章数量:1304892
I need to overwrite the show_on_front, page_on_front, page_for_posts options values for some reasons. I am setting show_on_front to 'page' and the other both to two different page id. If I change these settings in Administration > Settings > Reading panel to the same values as I do programmatically, the front page loads the front-page.php template. Otherwise the front page loads the page.php template. What am I doing wrong?
add_filter('pre_option_show_on_front', 'static_front_page');
function static_front_page() {
return 'page';
}
add_filter('pre_option_page_on_front', 'page_on_front');
function page_on_front() {
return 123;
}
add_filter('pre_option_page_for_posts', 'page_for_posts');
function page_for_posts() {
return 123;
}
I know this is not best practice, but would love to get this done this way.
Another problem when setting it per filter, is that is_front_page() isn´t working correct after it.
I need to overwrite the show_on_front, page_on_front, page_for_posts options values for some reasons. I am setting show_on_front to 'page' and the other both to two different page id. If I change these settings in Administration > Settings > Reading panel to the same values as I do programmatically, the front page loads the front-page.php template. Otherwise the front page loads the page.php template. What am I doing wrong?
add_filter('pre_option_show_on_front', 'static_front_page');
function static_front_page() {
return 'page';
}
add_filter('pre_option_page_on_front', 'page_on_front');
function page_on_front() {
return 123;
}
add_filter('pre_option_page_for_posts', 'page_for_posts');
function page_for_posts() {
return 123;
}
I know this is not best practice, but would love to get this done this way.
Another problem when setting it per filter, is that is_front_page() isn´t working correct after it.
Share Improve this question edited Mar 6, 2017 at 17:49 Status4 asked Mar 6, 2017 at 17:35 Status4Status4 337 bronze badges1 Answer
Reset to default 1Ok, got it working. I was returning a property of a serialized option within the callbacks for the filters:
add_filter('pre_option_page_on_front', 'page_on_front');
function page_on_front() {
$options = get_option('theme_options');
return $options['page_on_front'];
}
add_filter('pre_option_page_for_posts', 'page_for_posts');
function page_for_posts() {
$options = get_option('theme_options');
return $options['page_for_posts'];
}
The returend values were numbers, but strings. Typecasting them to int got it working.
本文标签: filtersManipulating showonfrontpageonfrontpageforposts and template hierarchy
版权声明:本文标题:filters - Manipulating show_on_front, page_on_front, page_for_posts and template hierarchy 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741794515a2397856.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论