eighteen73/virtual-pages

A helper library for creating WordPress custom permalink pages. Based off https://gist.github.com/gmazzap/1efe17a8cb573e19c086

dev-main 2024-03-28 16:13 UTC

This package is auto-updated.

Last update: 2024-04-28 16:27:33 UTC


README

Allows for creation of ad-hoc URLs from plugins, while following all standard WP page and content hooks.

Shortcodes can be included in content, allowing other code to be dynamically introduced where needed.

An example

<?php

\Eighteen73\VirtualPages\VirtualPages::init();

add_action( 'virtual_pages', function ( \Eighteen73\VirtualPages\Controller $controller ) {

   // first page
   $controller->addPage( new \Eighteen73\VirtualPages\VirtualPage( "/custom/page" ) )
     ->setTitle( 'My First Custom Page' )
     ->setContent( '<p>Hey, this is my first custom virtual page!</p>' )
     ->setTemplate( 'custom-page.php' );

   // second page
   $controller->addPage( new \Eighteen73\VirtualPages\VirtualPage( "/my/custom/gallery" ) )
     ->setTitle( 'My Custom Gallery Virtual Page' )
     ->setContent( '[gallery ids="27,35,48"]' )  // is possible to put shortcodes in content
     ->setTemplate( 'custom-gallery.php' );

} );

Credits

Heavily based on https://gist.github.com/gmazzap/1efe17a8cb573e19c086 by Giuseppe Mazzapica.