WordPress.org

Ready to get started?Download WordPress

Forums

All in One SEO Pack
[resolved] Title and description for specific category (5 posts)

  1. optimus203
    Member
    Posted 1 year ago #

    I would like to specify custom titles and descriptions for post categories (I'm redirecting certain pages to category pages that lists posts in that category). Is this possible? Right now, I only see a global option to include category name along with site title, but I can to customize contents of meta title and description a bit more. Thanks for the time.

    http://wordpress.org/extend/plugins/all-in-one-seo-pack/

  2. Peter Baylies
    Member
    Plugin Author

    Posted 1 year ago #

    There currently isn't support for this in the plugin, although you should be able to add it using PHP by filtering aioseop_title and aioseop_description; we are planning on adding better support for this integrated into All In One SEO Pack. Below is a basic example of how you'd go about adding a filter here.

    add_filter('aioseop_title', 'sfwd_custom_title');
    
    function sfwd_custom_title($title) {
       if ( is_category() ) {
            $title = "Custom Category Title";
       }
       return $title;
    }
  3. optimus203
    Member
    Posted 1 year ago #

    So if I wanted to assign category title to categories with specific names, I would do something like this?

    add_filter('aioseop_title', 'sfwd_custom_title');
    
    function sfwd_custom_title($title) {
       if ( is_category() == "CategoryName" ) {
            $title = "Custom Category Title";
       }
       if ( is_category() == "CategoryName2" ) {
            $title = "Custom Category Title";
       }
       return $title;
    }
    
    add_filter('aioseop_description', 'sfwd_custom_desc');
    
    function sfwd_custom_desc($title) {
       if ( is_category() == "CategoryName" ) {
            $description = "Custom Category Description";
       }
       if ( is_category() == "CategoryName2" ) {
            $description = "Custom Category Description";
       }
       return $description;
    }
  4. Peter Baylies
    Member
    Plugin Author

    Posted 1 year ago #

    That's close; but actually that should be is_category( "CategoryName" ) - check the Codex page for is_category() here.

    add_filter('aioseop_title', 'sfwd_custom_title');
    
    function sfwd_custom_title($title) {
       if ( is_category( "CategoryName" ) ) {
            $title = "Custom Category Title";
       } elseif ( is_category( "CategoryName2" ) ) {
            $title = "Custom Category Title 2";
       }
       return $title;
    }
  5. optimus203
    Member
    Posted 1 year ago #

    Brilliant. That worked perfectly. Thanks for the help Peter.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic