fbpx

Make custom plugin front end page in wordpress

It since a while where i got some project and make those project as my learning challenge to learn wordpress (WP) framework to create plugin. the reason why i eager to learn this framework is as i write below :
1.  it easy to create those plugin in wordpress.

2. wp is very maintainable because there a strong dedicated team behind it that really concern to maintance the wp itself

3. i dont dont like reinventing the wheel. because wp have very great ecosystem i want to use that everthing in those ecosystem to support my website.

 

of course anything new there alot of new problem. the challenge in creating the plugin in wp is to make some front end page. it not easy though but as wp widely used by developer the reference is very easy to find. Unfortunately the reference itself is not too detail to implement. here i want to share on how to create custom page for your plugin in frontend.

enough the talk here what i learn to create new plugin front end page without using theme / templating in wp :

  1. you need to define the php function that run in wp  by using this script :
 //make custom frontend page
add_action( 'wp_head', 'my_custom_public_page' );

 

2. define what those my_custom_public_page function really doing in :

 function my_custom_public_page()
      {
            if(isset($_GET['room_type'])){      
                  $dir = plugin_dir_path( __FILE__ );
            include($dir."custom_page.php");
           
            }
      }

 

3. create file custom_page.php in your plugin directory

 <html>
 <h1> Horray </h1>


</html>

to access those page you need to type in address browser bar this link :

http://yourhost/?room_type=1

 

congrat. we made it. …

 

reference :

  1. https://wordpress.stackexchange.com/questions/9870/how-do-you-create-a-virtual-page-in-wordpress
  2. http://www.wpbeginner.com/wp-tutorials/how-to-add-a-shortcode-in-wordpress/