How to include meta keywords on dynamically created page in WordPress?
How to include meta keywords on dynamically created page in WordPress?
Using a single service page, I have created 50 location based service page dynamically. I dont know how to add meta keywords for each location based pages dynamically.
I used arrays to display the location name on content using short code functionality. Below you can find the code, which I'm using now.
Below is the array
$STATES_ARRAY = array(
array(
"slugCode"=> "florida",
"name"=> "Florida",
"stateCode"=> "FL",
"plans"=> "plan 1, plan 2"
),
array(
"slugCode"=> "georgia",
"name"=> "Georgia",
"stateCode"=> "GA",
"plans"=> "plan 1, plan 2"
),
);
define('STATES_ARRAY', $STATES_ARRAY);
Below is the short code function
function mp_usstate_name_shortcode() {
$usstate_name = "";
$chosen_state = [];
global $STATES_ARRAY;
$state = array_filter($STATES_ARRAY, function($state) {
return $state["slugCode"] === get_query_var("usstate");
});
if(count($state) > 0){
$chosen_state = array_pop($state);
if(!empty($chosen_state) ){
$usstate_name = $chosen_state["name"];
}
}
return $usstate_name;
}
add_shortcode('US_STATE_NAME', 'mp_usstate_name_shortcode');
Is it possible to use same set of arrays by including various meta keywords in it?? I want to add meta keywords on all my location based Page.
Right now I generated location based page for my 2 service pages. I want to include location based keywords on both service pages.
Yes, you can add the meta keywords to the array. If you have Yoast SEO installed, you can use their API to update meta title and meta description dynamically: https://developer.yoast.com/features/seo-tags/titles/api/ (no one bothers with meta keywords anymore)
For example, to update the meta title dynamically:
function karthy_prefix_filter_title( $title ) {
if ( is_page( '**slug-of-page**' ) ) {
global $STATES_ARRAY;
$state = array_filter($STATES_ARRAY, function($state) {
return $state["slugCode"] === get_query_var("usstate");
});
if(count($state) > 0){
$chosen_state = array_pop($state);
if(!empty($chosen_state) ){
$title = $chosen_state["seo_title"];
}
}
return $title;
}
add_filter( 'wpseo_title', 'karthy_prefix_filter_title' );
January 13, 2024
Turbo Multi-language Translator
Make the better internet purchasing globaly
Turbosify SEO Speed Booster
5.0 (7)•Free plan available
Get better conversions by improving store loading speed
Installed
Turbo Multi-language Chat - AI Customer service in one hand
January 13, 2024