I created a WP plugin that uses a query string to pull page data based on what the visitor selected. Obviously, this "mimics" additional pages, but the page title does not change from the set of headers in WP Admin.
I am trying to connect to wp_title to change the title tag on the fly, but cannot make it work.
The following function works:
public function custom_title($title) { return 'new title'; } add_filter( 'wp_title', array($this, 'custom_title'), 20 );
As soon as I try to pass a variable to it, it fails.
public function custom_title($title, $new_title) { return $new_title; }
WordPress complains that it skips the second argument, I think it makes sense since the function is called when the page loads ... I was hoping I could do something like $this->custom_title($title, 'new title); inside your plugin, but it doesn't look like it will be possible?
I posted this here because I consider this a common PHP class problem.
Can I globalize the returned variable, for example. I want to return the "title" column from the query in another function like $query->title
When the function starts, it returns data from the database
public function view_content() { $query = $this->db->get_row('SELECT title FROM ...'); $query->title; }
Now I need to specify $ query-> title as the page title.
public function custom_title() { if($query->title) { $new_title = $query->title; } }
php class wordpress title
Goodbytes
source share