8

I am trying to programmatically set the 'page_on_front' option with the id value retrieved from the get_page_by_title command...

$homepage = get_page_by_title( 'Front Page' );
update_option('page_on_front', $homepage);
update_option('show_on_front', 'page');

This isn't working, can anyone help?

20

get_page_by_title() returns an object.

Use $homepage->ID.

You should also check if you really got a usable return value:

$homepage = get_page_by_title( 'Front Page' );

if ( $homepage )
{
    update_option( 'page_on_front', $homepage->ID );
    update_option( 'show_on_front', 'page' );
}

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.