Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

i have

add_options_page('Post Products Settings', 'Post Products Settings', 'administrator', 'pp_settings', 'pp_settings_page');

anyway i can get whats specified in the 1st parameter for use in my page header? i know i can hard code it tho, but just curious

share|improve this question
    
That first parameter will be your page title ... Have you tested this code? What exactly are you trying to accomplish and what are you seeing that's not the behavior you want? –  EAMann Sep 13 '10 at 14:31
    
Yeah we need some more information to really help you generate the code to solve your problem. –  curtismchale Sep 13 '10 at 15:04
1  
In your page callback function you have to output a h1 or h2 inside the page content itself. The question is how to fetch that string programatically instead of duplicating it. –  jeremyclarke Sep 13 '10 at 15:35
1  
yes jeremy is right. i am wondering if there is any way i can get what is entered in the 1st parameter by code so i can output it in the h2 –  Jiew Meng Sep 14 '10 at 10:28

2 Answers 2

up vote 4 down vote accepted

There are a few ways you can do this. My preferred way of doing this is using Object Oriented Programming (OOP) to structure the plugin. For example, I might do this:

class JPBTitle {
  var $page_title = "Post Products Settings";

  function __construct(){
    add_action( 'admin_menu', array( $this, 'admin_menu' ) );
  }

  function admin_menu(){
    add_options_page( $this->page_title, $this->page_title, 'administrator', 'pp_settings', array( $this, 'pp_settings' ) );
  }

  function pp_settings(){
    echo "<div class='wrap'>\n\t<h2>$this->page_title</h2></div>";
  }
}

$JPBTitle = new JPBTitle();

There are many many advantages to using object oriented programming in plugins; however, if you don't want to use OOP, I would suggest either setting a global variable or defining a constant with the value you want to use for that string.

share|improve this answer

You can call get_admin_page_title(). If the global variable $title is not empty it will return that, otherwise it will set it and return the value.

It is called at the top of admin-header.php and then goes through esc_html(), so if you want the raw value you should empty $title and call the function again.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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