I've googled myself to death with this problem for hours now, so I'm trying to get some help by creating my own question hoping you can help me :)
I have written a Plugin which needs to output its content on a blank page.
I could use a shortcut, but then template header and footer will be loaded to. I don't want to create a (blank) custom template file. This would need more work for the user then just installing the Plugin.
So I found this code on stackexchange which creates a permalink and outputs the content to it: (direct Link: Generate custom output for page/URL in a plugin)
<?php
/*
Plugin Name: Custom output
Description: A module to test the custom output. To test: http://your_wordpress_site.com/customop_uri_path
Version: 1.0
Author: Danilo Silva
Author URI: http://danilocgsilva.me
*/
// Write a new permalink entry on code activation
register_activation_hook( __FILE__, 'customop_activation' );
function customop_activation() {
customop_custom_output();
flush_rewrite_rules(); // Update the permalink entries in the database, so the permalink structure needn't be redone every page load
}
// If the plugin is deactivated, clean the permalink structure
register_deactivation_hook( __FILE__, 'customop_deactivation' );
function customop_deactivation() {
flush_rewrite_rules();
}
// And now, the code that do the magic!!!
// This code create a new permalink entry
add_action( 'init', 'customop_custom_output' );
function customop_custom_output() {
add_rewrite_tag( '%customop_uri_path%', '([^/]+)' );
add_permastruct( 'customop_uri_path', '/%customop_uri_path%' );
}
// The following controls the output content
add_action( 'template_redirect', 'customop_display' );
function customop_display() {
if ($query_var = get_query_var('customop_uri_path')) {
header("Content-Type: text/plain");
echo 'This is my custom content!!!!';
exit; // Don't forget the exit. If so, WordPress will continue executing the template rendering and will not fing anything, throwing the 'not found page'
}
}
This example works very well, except it does not only output the content to "customop_uri_path", it creates the output on ALL pages except the home-page. So the whole website gets screwed up.
I have created a new help-thread in order to get more ideas on how to create such an output for my plugin.
Can I load a specific template file just for the plugin, so the shortcode will also generate a blank page? Or is there a mistake in the code-example?
I'm thankful for all the help you can get me.
customop_display
than have some general issue. At least to me the code looks conceptually right.