• I am writing a plugin to allow people change basically find-and-replace using url queries.
    For ease of access, I need to be able to grab the page content (the body stuff typed in the editor) instead of using “echo str_replace” in my php code for my plugin.

    Is there any way to get the page content from a shortcode?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter kjgbriggs

    (@kjgbriggs)

    Bump

    Thread Starter kjgbriggs

    (@kjgbriggs)

    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');
    
    ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Getting page content from Shortcode’ is closed to new replies.