0

I have a profile page, it is a template. Every time when I click one of a doctor, the profile page will show the specific doctor info by passing a query string. Something like profile?doctorName=abc. I have rewrote to profile/abc.

Now the page title is "profile | blog name", But I would like to change the title to "abc(doctor's name) | hospital name".(Different doctor is in different hospital). This is my code below, and I tried to put it in the function.php and the profile template:

   <title><?php if (is_page( physician_single_pg()))
           {
            echo something               ////How to get the doctor name
            echo " | ".(our_doctors()); //the hospital name, get from the plugin                
           }
          else
            {
            wp_title( '|', true, 'right' );
            }
          ?>
    </title>

I am thinking maybe I can push the query string to the plugin and pull it out in the header. But I don't know how to do that.

I didn't get any luck. Please help, every suggestion is welcome. Thank you.

3
  • Oh, I figured it out, just use get query var to get the doctor name.
    – Pluto
    Mar 27, 2013 at 18:47
  • Care to post your solution as a proper answer? Mar 27, 2013 at 19:28
  • This is not the best answer, I am still wondering how to make this edition in the plugin:). Right now, it is in the header.php, which means uses cannot change the title. But yes, at least this is a solution.
    – Pluto
    Mar 27, 2013 at 21:14

1 Answer 1

2

use the wp_title filter. just remove all your code from header.php and put this into your plugin instead:

add_filter( 'wp_title', 'my_wp_title', 10, 2 );

function my_wp_title( $title, $sep = '|' ) {

    if ( is_page( physician_single_pg() ) and get_query_var( 'doctor' ) ) {
        $doctor = get_query_var( 'doctor' );
        $title = ... // here you put your code to build your title from the doctor & hospital name
    }

    return $title;

}

add_filter( 'query_vars', 'my_query_vars' );

function my_query_vars( $vars ) {

    $vars[] = 'doctor';

    return $vars;

}
4
  • Thank you Simon, I tried this code. It works. I have a question: it cannot display the query string properly. For the doctor name, I have to pull a query string from the current page. Is there any way I can get that value from the plugin?
    – Pluto
    Mar 28, 2013 at 21:39
  • The description is at the top of the first post.
    – Pluto
    Mar 28, 2013 at 21:40
  • i've added a function to add your query variable and added the code to check/retrieve its value. let me know if that works. Mar 29, 2013 at 15:21
  • It works! Okay, now I know how to pull a data from other page to plugin. Thank you!
    – Pluto
    Apr 4, 2013 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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