I know how to do it with apache/mod_proxy, but I can't use mod_proxy on our shared host. So no .htaccess solutions.
Currently I have the following code in child theme's page.php
global $post ;
if( needs_replacement( $post ) ) {
$post_name = $post->post_name ;
$from_url = create_url( $post );
$r = wp_remote_get( $from_url);
echo wp_remote_retrieve_body( $r );
exit(0);
}
require_once( get_template_directory() . '/page.php' );
?>
And it works. I am wondering what is the right way of doing this. $from_url is from the same server.
Example:
$post =
$from_url = /?sec=hello-world
Making it clear, what I want to develop is a method that can get the rendered page content when I pass a URL. So something like:
function wp_get_url_content( $url ) {
....
}
The $url
will always be a URL from the same server.
I know how to do it with apache/mod_proxy, but I can't use mod_proxy on our shared host. So no .htaccess solutions.
Currently I have the following code in child theme's page.php
global $post ;
if( needs_replacement( $post ) ) {
$post_name = $post->post_name ;
$from_url = create_url( $post );
$r = wp_remote_get( $from_url);
echo wp_remote_retrieve_body( $r );
exit(0);
}
require_once( get_template_directory() . '/page.php' );
?>
And it works. I am wondering what is the right way of doing this. $from_url is from the same server.
Example:
$post = https://example/docs/hello-world
$from_url = https://example/supp/?sec=hello-world
Making it clear, what I want to develop is a method that can get the rendered page content when I pass a URL. So something like:
function wp_get_url_content( $url ) {
....
}
The $url
will always be a URL from the same server.
Have WordPress (which creates the web server responses) respond with a redirect (via a call to wp_redirect()
). Put as the first thing in header.php
global $post;
if( needs_replacement( $post ) ) {
$from_url = create_url( $post );
wp_redirect( $from_url );
exit(0);
}
require_once( get_template_directory() . '/page.php' );
?>
(Note that you have to this first thing; otherwise, attempts to redirect will get ignored or more likely cause errors.)
(Thought of another approach)
Use a WordPress hook, and a call to set_query_var()
.
Something like
function add_my_query_vars () {
set_query_var('sec', 'hello world');
}
add_action('pre_get_posts','add_my_query_vars');
(This does make some likely assumptions about how the plugin handles query variables.)
needs_replacement
andcreate_url
do and how do they work? – Tom J Nowell ♦ Commented Feb 22, 2019 at 15:21https://example/supp/?sec=hello-world
from URLhttps://example/docs/hello-world
. the URLhttps://example/docs/hello-world
is a wordpress page. If I open it it shows me the page contents but without the additional menus provided byhttps://example/supp/?sec=hello-world
. So whenever a user goes tohttps://example/docs/hello-world
I want to show the content he gets when usinghttps://example/supp/?sec=hello-world
. – Dakshinamurthy Karra Commented Feb 22, 2019 at 16:16