0

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.

0

Ok, 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.