Hello!
Here's how I would do it.
If you want to use category name as meta title and category description as meta description, add this to your functions.php.
function wm_meta_title_category($title) {
if (osc_is_search_page()) { // If we are on search page...
$category = osc_search_category_id(); // Get current category.
if (array_key_exists(0, $category)) { // If current category isn't empty...
View::newInstance()->_exportVariableToView('category', Category::newInstance()->findByPrimaryKey($category[0]));
$title = osc_category_name(osc_current_user_locale()); // Meta title is now category title.
}
}
return $title; // If none of the criterias match, set default meta description.
}
osc_add_filter('meta_title_filter', 'wm_meta_title_category');
function wm_meta_description_category($description) {
if (osc_is_search_page()) { // If we are on search page...
$category = osc_search_category_id(); // Get current category.
if (array_key_exists(0, $category)) { // If current category isn't empty...
View::newInstance()->_exportVariableToView('category', Category::newInstance()->findByPrimaryKey($category[0]));
if(!empty(osc_category_description(osc_current_user_locale()))) { // If category description isn't empty...
$description = osc_category_description(osc_current_user_locale()); // Meta description is now category description.
} else { // If category description is empty...
$description = osc_category_name(osc_current_user_locale()); // Meta description is now category title.
}
}
}
return $description; // If none of the criterias match, set default meta description.
}
osc_add_filter('meta_description_filter', 'wm_meta_description_category');
If you want to add custom meta title and meta description for specific categories directly in the file, add this to your functions.php.
function wm_meta_title_category($title) {
if (osc_is_search_page()) { // If we are on search page...
$category = osc_search_category_id(); // Get current category.
if (array_key_exists(0, $category)) { // If current category isn't empty...
switch($category) {
case 1:
$title = 'Title for category with id 1';
break;
case 2:
$title = 'Title for category with id 2';
break;
case 15:
$title = 'Title for category with id 15';
break;
}
}
}
return $title; // If none of the criterias match, set default meta description.
}
osc_add_filter('meta_title_filter', 'wm_meta_title_category');
function wm_meta_description_category($description) {
if (osc_is_search_page()) { // If we are on search page...
$category = osc_search_category_id(); // Get current category.
if (array_key_exists(0, $category)) { // If current category isn't empty...
switch($category) {
case 1:
$description = 'Description for category with id 1';
break;
case 2:
$description = 'Description for category with id 2';
break;
case 15:
$description = 'Description for category with id 15';
break;
}
}
}
return $description; // If none of the criterias match, set default meta description.
}
osc_add_filter('meta_description_filter', 'wm_meta_description_category');
Note for the second solution: just copy those 3 lines (case, title/description, break) and change ID and description for each one of your categories.
Perhaps it ain't the most sophisticated way of doing this, but otherwise, you would need a plugin with a database to store all custom titles and descriptions, etc.
Regards.