Update: I have tried a lot on this, and tried using the $content attribute to get the page content (with closing tag) but it isn’t working.
Below I have posted the code for the plugin, and the shortcode being used.
What happens is the body text isn’t visible, at all, if I use a url query, but when I don’t the only way to get stuff up is to use my error message.
I am not convinced the $content tag actually works how I am using it, and think the content is being lost somewhere.
I also need to stop the text from showing up in the editor, as in the page edit screen it also displays.
Shortcode
[legal-content]This is some =productname= product.[/legal-content]
Code
<?php
/**
* Plugin Name: Dynamic Legal Page
* Plugin URI:
* Description: This plugin allows developers to pass URL arguments to change page content.
* Version: 1.0
* Author: Kyle Briggs
* Author URI: https://www.kylebriggs.co.uk/
* License: LGPL
*/
add_filter('query_vars', 'parameter_queryvars' );
function parameter_queryvars( $qvars )
{
$qvars[] = 'productname';
return $qvars;
}
//Register Shortcode
function legal_content_function() {
?>
<div class="et_pb_row"">
<?php
//echo "<h1>Product Legal</h1>";
global $wp_query;
if (isset($wp_query->query_vars['productname']))
{
echo str_replace("=productname=", $wp_query->query_vars['productname'], "<h1>=productname= Legal</h1>");
//echo str_replace("=productname=",$wp_query->query_vars['productname'],"This is a =productname= legal document.");
echo str_replace("=productname=", $wp_query->query_vars['productname'], $content);
}
else
{
echo "<h1>Error</h1>";
echo "Please use URl query \"?productname=\" to display this page.";
}
}
function register_shortcodes(){
add_shortcode('legal-content', 'legal_content_function');
}
add_action( 'init', 'register_shortcodes');
?>