• Resolved redone975

    (@redone975)


    I’m working with a 3.1 multisite CMS implementation. I’m ready to hand over the site soon and I’ve been re-evaluating how the sub sites will be set up.

    Right now, when a user creates a new site, they have to go through the following steps to set up the homepage:

    1. Add a new page called “Home”
    2. Go to Settings > Reading and select “Home” as the static front page option.

    It would be great to either rename the “Sample Page” page (and update it’s permalink) or automatically add the “Home” page.

    Is this possible via functions.php?

Viewing 11 replies - 1 through 11 (of 11 total)
  • phantomdentist

    (@phantomdentist)

    I would also be very interested n knowing how and if you can add pages via functions.php

    Thread Starter redone975

    (@redone975)

    Thanks for the links.

    How do I use the wp_insert_post within the functions.php to fire once on the initial setup of the site? I placed it within the functions.php file to test it out creating a page called “homepage” and when I logged into the site, there were 6 “homepages” created by this inclusion.

    Thanks again for the direction and any additional information you may be able to provide.

    Thread Starter redone975

    (@redone975)

    Ran across a hook called after_setup_theme in this article. Maybe this is the way to go?

    http://justintadlock.com/archives/2010/12/30/wordpress-theme-function-files

    hmm…. seems duplicate posting would be an issue, I’m not sure how to handle that, but I’ll look around.

    I’ve only worked with wp_insert_post recently, I used do_action on it, but it was for a post from front end form, so I think the usage will be different

    http://wpsnipp.com/index.php/functions-php/create-page-on-theme-activation/#

    May be able to help you it seems, only fires the page creation on theme activation.

    Still I worry that if you activate, deactivate, then re-activate, you will still get multiple?

    Although looking at that code, it appears to run a check, so this might be your solution

    Thread Starter redone975

    (@redone975)

    Rev. Voodoo… Thank you so much! I just tried the link from your last post and that worked perfectly for creating a new page.

    I’m going to now try to incorporate the static front page code.

    BTW, I de-activated/re-activated the theme a couple of times to see if it would create multiple posts. It did not. Works great.

    Thanks for reporting back! As I had never personally done this, I like to know what works or doesn’t for future questions.

    Thread Starter redone975

    (@redone975)

    I implemented the static front page and it worked smoothly. Here’s the summary:

    Goal
    Implementing code within the functions.php file that woud:

    1. dynamically create a page called “Home”
    2. dynamically set this new page as the static front page

    Here’s the final code I used.

    [Code moderated as per the Forum Rules. Please use the pastebin]

    As the note mentions, just drop that in a pastebin and report the link.

    I’m sure others would appreciate the effort.
    And then mark the thread resolved if you are happy (from the dropdown on the right), it will let future searches know the thread contains good info!

    Thanks for reporting back

    Thread Starter redone975

    (@redone975)

    Ah, here’s the link to the pastebin:
    http://pastebin.com/dkwu0m2Z

    Thanks again.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Is it possible to create a page via functions.php?’ is closed to new replies.