I’ve got some pages with url’s like this: /state/state-name/ and /city/city-name/ that’s built in WordPress.
The states and city’s are dynamically added when they have been populated by a user entering that information.
The URL parameter of “state-name” & “city-name” determines the content that will dynamically show on that page. However, my meta title & description for all those pages is statically set. Is there a way I can dynamically set the meta title & description based on the page content?
I’ve tried the following, but can only get it to work for one page (/state/).
add_filter( 'wpseo_title', 'custom_title' );
function custom_title( $title ) {
$uri = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
`if ( '/state/' === $uri ) {`
`return $title . ' - Some text';`
}
return $title;
}
`add_filter( ‘wpseo_description’, ‘custom_meta’ );
function custom_meta( $description ) {
$uri = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
if ( '/state/' === $uri ) {
return $description . ' state meta.';
}
return $description;
}`
Works only for url /state/.
How to get it to work with other dynamic url’s like;
/state/something1/
/state/something2/
/state/etc/
/city1/something1/
/city1/something2/
/city1/etc/
Could it be done with something like a wildcard, ie
/state/.()/
/city/.()/
Any pointers appreciated.
Yoda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.