Development > Development

Proper META Description for Categories [Solved]

(1/5) > >>

Aficionado:
Hi, i would appreciate some help here. Trying to make OsclassWizards theme to display proper META Descriptions in categories. Right now it shows the metas from the first ad listing...

The Code in Common/head.php is:


--- Code: ---<title><?php echo osc_esc_html(seo_meta_title()) ; ?></title>
<?php if( meta_description() != '' ) { ?>
<meta name="description" content="<?php echo osc_esc_html(meta_description()); ?>" />
<?php } ?>
<?php if( meta_keywords() != '' ) { ?>
<meta name="keywords" content="<?php echo osc_esc_html(meta_keywords()); ?>" />
<?php } ?>
--- End code ---

If anybody could help ?

Thanks

teseo:
***CORRECTED***

Hi,

The function meta_description() ends with a filter that you might use:


--- Code: ---return (osc_apply_filter('meta_description_filter', $text));
--- End code ---

Let's think you want to use there the Description field that every category has available:

Add this at the very bottom of your theme functions.php:
Notes:
1.- Take care not to leave blank lines after this.
2.- If your theme functions.php doesn't end with ?> skip first line of my code.


--- Code: ---<?php
function cust_categories_meta_description($text) {
    if (osc_is_search_page()) {
        $categories = osc_search_category_id();
        if (!empty($categories)) {
            View::newInstance()->_exportVariableToView('category', Category::newInstance()->findByPrimaryKey($categories[0]));
            $text = osc_category_description(osc_current_user_locale());
        }
    }

    return $text;
}

osc_add_filter('meta_description_filter', 'cust_categories_meta_description');
?>

--- End code ---

Regards

Aficionado:
Thanks (as usual) Teseo, i will try all that and report back.

Aficionado:
Seems to work very well, thanks Teseo

teseo:
You're welcome. :) Would you mind changing the title of this thread to  "Proper META Description for Categories [Solved]"?

(Given that this procedure is universal, not only for Osclass Wizards theme).

Thanks, regards

Navigation

[0] Message Index

[#] Next page

Go to full version