Created
July 4, 2013 13:53
-
-
Save strangerstudios/5927953 to your computer and use it in GitHub Desktop.
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…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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