You should insert the following code in functions.php of your theme.
/* Global matrix for shortcodes/content for every page */
$locations = array(
array(
'location' => 'location 1',
'telephone' => '0121 34838383',
'email' => '[email protected]'
),
array(
'location' => 'location 2',
'telephone' => '92939393',
'email' => '[email protected]'
),
array(
'location' => 'location 3',
'telephone' => '343443433',
'email' => '[email protected]'
),
array(
'location' => 'location 4',
'telephone' => '343433',
'email' => '[email protected]'
),
array(
'location' => 'Global Matrix Page',
'telephone' => '222 33 22',
'email' => '[email protected]'
)
);
function telephone_shortcode() {
global $locations;
$title = get_the_title();
$key = array_search($title, array_column($locations, 'location'));
if ($key)
return $locations[$key]['telephone'];
else
return '';
}
add_shortcode('telephone', 'telephone_shortcode');
function email_shortcode() {
global $locations;
$title = get_the_title();
$key = array_search($title, array_column($locations, 'location'));
if ($key)
return $locations[$key]['email'];
else
return '';
}
add_shortcode('email', 'email_shortcode');
/* End of Global Matrix */
$locations array contains your locations (page titles), telephones and emails. You can expand it as far as you need.
Below are two fucntions defining shortcodes on your pages: [telephone] and [email]. They are similar. Each fucntion get the title of current page (get_the_title) and looks for it in $locations array, then returns corresponding telephone or email.
Your page can be like that:
telephone = [telephone]
email = [email]
Code is tested, you can see result here.