Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save messica/8742314 to your computer and use it in GitHub Desktop.
Save messica/8742314 to your computer and use it in GitHub Desktop.
<?php
/*
Template for adding a shortcode page to a plugin. Steps:
1. Include this file.
2. Add [my_page_shortcode] shortcode to a page of the site.
3. Navigate to the page on the front end.
Be sure to change the name of the shortcode and the function names below.
Add all "preheader" code to the preheader section. This is code that will process before the wp_head call and should include form processing, etc.
All frontend code should go in the page template section. We use output buffering to capture anything echo'd here and return it to the shortcode to be swapped into the shortcode space.
*/
/*
Preheader
*/
function my_page_preheader()
{
if(!is_admin())
{
global $post, $current_user;
if(!empty($post->post_content) && strpos($post->post_content, "[my_page_shortcode]") !== false)
{
/*
Preheader operations here.
*/
}
}
}
add_action("wp", "my_page_preheader", 1);
/*
Shortcode Wrapper
*/
function my_page_shortcode($atts, $content=null, $code="")
{
ob_start();
/*
Page Template HTML/ETC
*/
?>
<?php
$temp_content = ob_get_contents();
ob_end_clean();
return $temp_content;
}
add_shortcode("my_page_shortcode", "my_page_shortcode");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment