0

I have a WordPress marketing site (www.example.com) and a backend app site (app.example.com). What I am trying to do is this: if some body goes to the URL:

www.example.com/profile/<<profileId>>

I want to create a page that has mostly generic content and one iframe with src

my.example.com/profile/<<profileId>>

Now I have 2 problems:

  1. Can a page have dynamic URL? If i try to set the URL to www.example.com/profile/*/ it becomes www.example.com/profile/
  2. If I do get the page to work, how to pass profileId to the iframe src?

Can somebody please direct me to a plugin/solution?

2 Answers 2

1

Step 1:

Create a page with slug 'profile' in your WordPress Dashboard.

Step 2

Use this function to register profileId var.

add_filter('query_vars', 'wp233_query_vars');
function wp233_query_vars( $query_vars ){
    $query_vars[] = 'profileId';
    return $query_vars;
}

And add a rewrite rule to wordpress like this:

add_action( 'init', 'wp233_add_rewrite_rules' );
function wp233_add_rewrite_rules() {

  add_rewrite_rule(
    '^profile/([^/]+)?$',
    'index.php?pagename=profile&profileId=$matches[1]',
    'top');

}

Step 3

Now you can access the query var like this:

http://yoursite.com/profile/xxxx/

Now you should be able to extract the profileId by hooking in suitable action

Example

add_action( 'template_redirect', 'wp233_get_profile_id' );
function wp233_get_profile_id() {

   $profile_id = get_query_var( 'profileId' );
   if ( $profile_id ) {

    // do some magic work. you now captured the profile id
    // which was passed to url.com/profile/{ID}/ -> here.

   }

}
0

This shouldn't be too difficult. First you have to get the <<profileID>> part of the current page/post. How to get it, depends on what it is and where in your template you are calling it. If, for instance, "profile" is a custom post type, then <<profileID>> is the slug of the post, which you could retrieve like this, presumably in single.php:

$profileID = get_post_field( 'post_name', get_post());

The rest is straightforward PHP:

echo '<iframe src="my.example.com/profile/' . $profileID '/></iframe>';

Now you have your page with the iframe and you want to display it without the slug. The answer to that is here.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.