Sunday, November 13, 2022
HomeWordPress Developmentplugin growth - Utilizing a Web page Template Not in Theme

plugin growth – Utilizing a Web page Template Not in Theme


My plugin creates (on demand through a ‘create template’ button) a web page template that’s saved in uploads/plugin-name folder (so it’s going to survive a plugin replace).

The plugin additionally creates (once more on demand) a put up that should use that template. It does this with the wp_create_post operate:

    $template_file = "/the/absolute/path/to/wp-content/uploads/plugin-name/custom-template.php";
    $new_page        = array(
        'post_type' => 'web page',
        'post_title' => 'The Customized Web page',
        'post_content' => $some_content,  // textual content for the content material, beforehand outlined
        'post_status' => 'publish',
        'post_author' => 1,
        'post_slug' => 'the-custom-page',
        'page_template' => $template_file,
    );
    $the_page_id = wp_insert_post($new_page);

The _wp_page_template meta worth is correctly saved within the postmeta desk for that put up ID, that document has the worth of absolutely the path to the {custom} template.

My challenge is with how to make sure that the {custom} web page makes use of the {custom} template. The docs usually are not clear whether or not the web page can use a template file (the posts’ _wp_page_template meta worth) with an absolute path, slightly than a path relative to the present theme.

The intent is to have a theme-independent template that can be utilized for the {custom} web page. I have been capable of correctly retailer the template meta worth for the put up, however cannot get the {custom} web page to make use of it – despite the fact that that {custom} template is proven within the ‘template’ dropdown for that web page.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments