plugin development – How to create templates for a custom module to show on the front end within my theme?

Question

I’d like to create a simple plugin with a form on the front end which submits the value of 3 fields into a DB table.

For the plugin, I’ve been using this answer:
https://wordpress.stackexchange.com/a/162476/77891

What I can’t get working now, is a template.

Within the main plugin file, I’ve added:

add_action( 'gm_virtual_pages', function( $controller ) {

    // first page
    $controller->addPage( new WEBPManagementPage( '/custom/page' ) )
        ->setTitle( 'My First Custom Page' )
        ->setTemplate( 'custom-page-form.php' );
} );

And my custom-page-form.php:

<?php 
echo "Test Echo";

?>
<p>Test</p>
<p>Echo</p> 

The title is being displayed (My First Custom Page).
But not my Test Echo.
How does a correct / working template file have to look like?

in progress 0
Chris 4 weeks 2021-08-19T23:43:34-05:00 0 Answer 0 views 0

Answer ( 1 )

    0
    2021-08-22T03:11:37-05:00

    Templates in wordpress just needs to be valid PHP files. You need to place your template inside theme ( or child theme directory ).

    Have you placed the template in plugin directory ? if yet it won’t work. https://gist.github.com/gmazzap/1efe17a8cb573e19c086

Leave an answer

Browse
Browse