Support » Plugin: Insert Pages » “Use a Custom Template” doesn’t show “Custom Template Filename” in builder

  • Resolved Wes Modes

    (@wmodes)


    Hi, thanks for the plugin. It works well when I am adding Gutenberg blocks.

    However, when using Insert Pages (v3.5.1) with Elementor (v2.9.3) or Beaver Builder (v2.3.1.1) and selecting “Use a Custom Template”, the resulting configuration window doesn’t show a “Custom Template Filename” field. The field below it labeled “Default Template” has no other choices and can’t be modified.

    I am using Insert method “Legacy”. My template file is named “template-thing.php” and is a template for the “thing” CPT. It is in the right directory and works well enough when I specify the filename for the shortcode and within Gutenberg.

    Here are screenshots.

    Is there something I’m missing? Or is there a way to register my template? I have the header at the top of my template file:

    <?php
    /*
     * Template Name: Thing Page
     * Template Post Type: thing
     *
     * Template for displaying an ad.
     *
     * @package understrap
     */
    ?>
    • This topic was modified 5 months, 2 weeks ago by Wes Modes.
    • This topic was modified 5 months, 2 weeks ago by Wes Modes.
    • This topic was modified 5 months, 2 weeks ago by Wes Modes.
Viewing 15 replies - 1 through 15 (of 16 total)
  • It appears that this selection box is disabled in the source:

    <select name="insertpage-template-select" id="insertpage-template-select" disabled="true">

    And in the rendered HTML of my version of Insert Pages:

    <select class="insertpage-template-select" name="widget-ipw[REPLACE_TO_ID][template]" id="widget-ipw-REPLACE_TO_ID-template" disabled="disabled">
    				<option value="all">Default Template</option>
    				
    	<option value="page-templates/blank.php">Blank Page Template</option>
    	<option value="elementor_canvas">Elementor Canvas</option>
    	<option value="elementor_header_footer">Elementor Full Width</option>
    	<option value="page-templates/empty.php">Empty Page Template</option>
    	<option value="page-templates/fullwidthpage.php">Full Width Page</option>
    	<option value="page-templates/left-sidebarpage.php">Left Sidebar Layout</option>
    	<option value="page-templates/both-sidebarspage.php">Left and Right Sidebar Layout</option>
    	<option value="page-templates/right-sidebarpage.php">Right Sidebar Layout</option>
    	<option value="single-test.php">Test Page</option>
    	<option value="single-thing.php">Thing Page</option>
    	<option value="content-thing.php">Thing Template</option>			</select>

    The template selections are there, but not available.

    I see now what you are doing, that you are setting the .insertpage-template-selectselect box disabled by default and changing it via JS when you select “template” in .insertpage-format-select.

    However, it appears that the JavaScript event handler in widget.js that includes:

    $( '.insertpage-template-select' ).removeAttr( 'disabled' );

    is not being called.

    Plugin Author Paul Ryan

    (@figureone)

    Thanks, we’ll take a look. Is this in the gutenberg block, or the classic editor?

    Plugin Author Paul Ryan

    (@figureone)

    Sorry, I see now. This is in Beaver Builder or Elementor.

    Plugin Author Paul Ryan

    (@figureone)

    Tracked down the custom hooks for Elementor and Beaver Builder to load the widget javascript in their respective editors:
    https://github.com/uhm-coe/insert-pages/commit/47c209ccdf6a94fb193758f12cb230b4d3ac0aab

    This will be included in the next release, but feel free to manually install the plugin from github if you want to test it or want it sooner!

    Plugin Author Paul Ryan

    (@figureone)

    Version 3.5.2 is out now with the change.
    https://wordpress.org/plugins/insert-pages/

    Thanks for the quick response. I’ll test it.

    Hi Paul,

    I’m working with Elementor. What I don’t see is my template (or a way to specify it).

    Here’s what I see in Edit Post:

    Insert Pages in Post Edit

    Here’s what I see in Elementor:

    Insert Pages in Elementor

    And here’s what I have at the top of my template, single-thing.php:

    <?php
    /**
     * Template Name: Thing Page
     * Template Post Type: thing,page,post
     
     *
     * Page for displaying a single ad.
     *
     * @package understrap
     */

    Should I see my template offered as an Insert Pages template? What am I missing?

    Is “Default Template” supposed to select the default template for the post_type? If so, it doesn’t seem to be selecting single-thing.php which is the default for my “thing” post_type.

    • This reply was modified 5 months ago by Wes Modes.
    • This reply was modified 5 months ago by Wes Modes.
    • This reply was modified 5 months ago by Wes Modes.
    • This reply was modified 5 months ago by Wes Modes.
    Plugin Author Paul Ryan

    (@figureone)

    Hm, you might have to create a new template file specifically for inserted Things. We typically can’t use the theme’s single-*.php templates, since they include the full html of the page, including headers and footers, which usually you don’t want in an inserted page.
    https://wordpress.org/support/topic/how-to-use-with-a-custom-template/

    That said, any php files with the Template Name header in the theme’s template directory should show up in the dropdown. Maybe your theme sets that location somewhere else?
    https://developer.wordpress.org/reference/functions/get_template_directory_uri/
    Or maybe WordPress prevents single-*.php named files from being custom templates, I’m not sure.

    “Default Template” is really just the Insert Pages default, which is to just print the page content.

    As I mentioned, I’m using a stripped down single-* page (single-thing.php) that doesn’t have most of the headers and footers.

    I’m switching from an understraps-child theme to understraps to make finding templates easier.

    As soon as I resolve another Insert Pages error (“Error loading block: Invalid parameter(s): attributes”), I will test again.

    Okay, I’ve learned a few things that will help others using Insert Pages to insert Custom Post Types (CPTs) using custom templates.

    1. You may have reason to create a custom page template for your CPT (e.g., single-mycpt.php). But you probably don’t want to use it with Insert Pages, unless you want to insert your nav, header, and footer with every inserted page.
    2. Many themes divide the business of presenting a post or CPT to a content template (e.g., loop-tepmlates/content-mycpt.php), which is a good practice. These templates are handling the presentation stuff inside the loop. This is the template you probably want to use for Insert Pages.
    3. However, if you use the content template to present your post or CPT, many WP functions only work within “The Loop” (<?php while ( have_posts() ) : the_post(); ?>) to know what post we are referring to. In many cases, there are alternatives that work outside of The Loop. If you don’t have an alternative, you can move your Loop out of the single template into your content template.
    4. For your content template to show up in the Insert Pages config block in Elementor or Beaver Builder, you need to include a standard template comment block at the top. Here’s the Post Type Template used since WP 4.7.
    5. If you use a child-theme, there is a possibility that your default template directory is set to the parent themes folder. In that case, if you put your templates in the child-theme’s folder they won’t be found by Insert Pages. That may change in the future, but I don’t have a workaround for that. (I shifted from a child theme to my own theme which used the excellent understraps theme as a jumping off point.)

    Hope that helps your users. Thanks for your responsiveness.

    Paul, I took what I wrote above and turned it into a tutorial that may help your users. I’d be honored if you read it and offered any comments.

    Using WordPress Insert Pages plugin with your Custom Post Types and Custom Templates

    Plugin Author Paul Ryan

    (@figureone)

    Awesome, thank you!! We’ll work next week on getting it listed and integrated.

    There are two anomalies I mention in the article that I want to check if they are intentional.

    Insert Pages will allow you to search for your CPT (handy!), but you have to specify the path to the custom content template.

    If you are using Elementor or Beaver Builder, you also get a new Insert Pages block. You will have to specify the slug of the CPT you want (no search this time), but if your template has a proper header and is in the templates directory, it will be offered as one of the custom template options.

    Are these two reversed behaviors what you see on your system?

    • This reply was modified 5 months ago by Wes Modes.
    Plugin Author Paul Ryan

    (@figureone)

    Probably not intentional, more a result of the organic growth of the plugin. Here’s the history:

    * Insert Pages started out as a simple plugin to embed other pages using the Shortcode API. Example: [insert page='sample-page' display='content'].
    https://developer.wordpress.org/apis/handbook/shortcode/

    * We then added a toolbar button to the Classic Editor (tinymce) that mimicked the existing “Insert/edit link” toolbar button. It included the ability to search for existing posts/pages. It also let you choose from a list of default renderers (e.g., content, excerpt), or custom renderers (existing Page Templates).
    https://kinsta.com/blog/wordpress-tinymce-editor/

    * Next we added a Widget that can be inserted in any sidebars registered in your theme.
    https://developer.wordpress.org/themes/functionality/widgets/
    https://developer.wordpress.org/themes/functionality/sidebars/

    * Independently, builder plugins like Beaver Builder and Elementor also interfaced with the Widget API and offered the ability to embed Widgets in page content (outside of Sidebars).

    * Finally, we added a Gutenberg block for the new editor.
    https://developer.wordpress.org/block-editor/developers/

    Each of these UIs (Classic Editor plugin, Widget, 3rd party plugin, and Gutenberg Block) has a slightly different context, so the Insert Pages features vary a bit. For example, Beaver Builder doesn’t load the core WordPress libraries that are present when using Widgets normally, so we have to manually include them to get the Custom Template dropdown to work:
    https://github.com/uhm-coe/insert-pages/blob/master/widget.php#L98-L107

    Hope that helps clarify how we got to here! It also means there’s a bunch of uses of Insert Pages out there that we don’t use ourselves, so pull requests and suggestions are always welcome.

Viewing 15 replies - 1 through 15 (of 16 total)
  • You must be logged in to reply to this topic.