I have some templates where I need to customize the page title according to user selection. I have added a filter hook to 'wp_title' tag following Codex docs but when the filter is applied I'm receiving a warning, I'd say an error, regarding parameters in the callback function declaration:
Warning: Missing argument 4 for buildPageTitle() in /Applications/XAMPP/xamppfiles/htdocs/.../blog/wp-content/themes/.../inc/my_functions.php on line 2
my_functions.php
1 <?php
2 function buildPageTitle($sep, $echo, $seplocation, $brand) {
3 return $brand.$sep;
4 }
5 ...
Template
<?php
/*
Template Name: By brand-countries
*/
$brandLabel = get_query_var('brand');
require_once('inc/dbConn.php');
require_once('inc/get_brand_data.php');
require_once('inc/my_functions.php');
add_filter('wp_title', 'buildPageTitle', 10, 4);
apply_filters('wp_title', $sep, false, $seplocation, $brand);
get_header();
?>
I can solve the problem declaring $brand var as global in the buildPageTitle() function but I prefer to pass it as a parameter as in other templates different vars will be needed