Reputation:
i would change the page title from a wordpress plugin site. the name comes from a function:
function subPage() {
$content = 'blabla';
$subPageTitle = 'Plugin Sub Page Dynamic';
return $content;
}
and the simple function for replace wp_title:
function wp_plugin_page_title($subPageTitle) {
$siteTitle = $subPageTitle;
return $siteTitle;
}
add_filter('wp_title', wp_plugin_page_title);
my problem is now: how i get the variable $subPageTitle in the function wp_plugin_page_title()?
Thanks a lot for ANY help!
EDIT: the code was not correct.
Upvotes: 0
Views: 343
Reputation: 2021
function subPage() {
$subPage = new stdClass();
$subPage->content = 'blabla';
$subPage->subPageTitle = 'Plugin Sub Page Dynamic';
return $subPage;
}
function wp_plugin_page_title($subPageTitle) {
$siteTitle = $subPageTitle . " " . subPage()->subPageTitle;
return $siteTitle;
}
add_filter('wp_title', wp_plugin_page_title);
Then you get the value by calling subPage()
echo subPage()->subPageTitle;
If you print_r the subpage you will see: stdClass Object ( [content] => blabla [subPageTitle] => Plugin Sub Page Dynamic )
Any values that are inside a function, they are encapsulated values if you need to reach them outside that function or you return them in an array or in an object.
Upvotes: 0