1

Hello wordpress gurus!

I want to be able to set the frontpage via a custom field.

So for example, in the new page area in the wordpress admin there is a custom field that displays "Set as frontage", instead of the user going to the Settings > Reading settings and setting the front page there they can do it via the new page.

I'm familiar with metaboxes and some coding but i'm not sure how i could implement this.

I also found this article on setting the front page programatically:

http://kuttler.eu/code/set-static-front-page-and-blog-page-programmatically-in-wordpress/

Its just the matter of putting it together with the custom field.

Help appreciated. Thanks

1

You can do it by updating 2 options.

<?php
    //This could be page or posts.
    update_option('show_on_front', '<posts/page>');

    //This one sets the page you want on front, won't work if the above option is set to 'posts'.
    update_option('page_on_front', '<id of the page you want to set as front page>');
?>

Though I cannot guarantee if this is safe and whether it will override the settings saved from the backend!

0

First things first - the front page is a system wide setting (by definition). Using a post meta is not the right choice. That said, you can use metaboxes to update the options itself. What you may want to do is to display a meta box that displays the current front page and also allows the user to set the current page as the front page from your metabox.

Have a look at options-reading.php to see what keys are used for front page and blog 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.