0

So it appears I am missing a vital pice of information somehow to make my custom post type title tag behave. everything else works fine.

my current - simple - scenario is this : wordpress 3.8, twentytwelve theme, wpizza plugin (I'm the author of this , so that's what the questions relates to really), nothing else

I registered the wppizza custom post type and taxonomies like so:

                /*******************************************************
                    [register custom post type]
                ******************************************************/
                public function wppizza_register_custom_posttypes(){
                    $labels = array(
                        'name'               => __( 'Menu Items', $this->pluginLocale),
                        'singular_name'      => __( 'WPPizza Menu Item', $this->pluginLocale ),
                        'add_new'            => __( 'Add New',  $this->pluginLocale ),
                        'add_new_item'       => __( 'Add New Menu Item',$this->pluginLocale ),
                        'edit'               => __( 'Edit', $this->pluginLocale ),
                        'edit_item'          => __( 'Edit Menu Item',$this->pluginLocale ),
                        'new_item'           => __( 'New Menu Item',$this->pluginLocale ),
                        'all_items'          => __( 'All Menu Items',$this->pluginLocale ),
                        'view'               => __( 'View', $this->pluginLocale ),
                        'view_item'          => __( 'View Menu Items',$this->pluginLocale ),
                        'search_items'       => __( 'Search Menu Items',$this->pluginLocale ),
                        'not_found'          => __( 'No items found',$this->pluginLocale ),
                        'not_found_in_trash' => __( 'No items found in the Trash',$this->pluginLocale ),
                        'parent_item_colon'  => '',
                        'menu_name'          => ''.$this->pluginName.''
                    );
                    /**add a filter to labels if you want to...**/
                    $labels = apply_filters('wppizza_cpt_lbls', $labels);       

                    $args = array(
                        'labels'        => $labels,
                        'description'   => sprintf( __( 'Holds %1$s  menu items data', $this->pluginLocale ), $this->pluginName ),
                        'show_ui'       => true,
                        'public'        => true,
                        'menu_position' => 100,
                        'menu_icon'     => defined('WPPIZZA_MENU_ICON') ? WPPIZZA_MENU_ICON : plugins_url( 'img/pizza_16.png', $this->pluginPath ),
                        'has_archive'   => false,
                        'hierarchical'  => false,
                        'supports'      => array( 'title', 'editor', 'author','thumbnail','page-attributes','comments'),
                        'taxonomies'    => array('') /* 'post_tag' for example*/
                    );
                    /**add a filter to arguments if you want to**/
                    $args = apply_filters('wppizza_cpt_args', $args);

                    register_post_type( $this->pluginSlug, $args );
                }
                /*******************************************************
                    [register taxonomy + taxonomy related functions]
                ******************************************************/
                public function wppizza_register_custom_taxonomies(){
                    $options = $this->pluginOptions;

                    /**********************
                        when using permalinks, we can either set the
                        parent to be a dedicated page (admin->settings)
                        .........
                    ***********************/
                    $sel_category_parent=get_post($options['plugin_data']['category_parent_page'],ARRAY_A);
                    /**********************
                    ........or use/set a default
                    (required as other pages wont work without it when permalinked
                    **********************/
                    if($sel_category_parent['post_name']==''){
                        $sel_category_parent['post_name']=$this->pluginSlugCategoryTaxonomy;
                    }

                      // Add new taxonomy, make it hierarchical (like categories)
                      $labels = array(
                        'name' => _x( 'WPPizza Categories', 'taxonomy general name' ),
                        'singular_name' => _x( 'Category', 'taxonomy singular name' ),
                        'search_items' =>  __( 'Search Categories' ),
                        'all_items' => __( 'All Categories' ),
                        'parent_item' => __( 'Parent Category' ),
                        'parent_item_colon' => __( 'Parent Category:' ),
                        'edit_item' => __( 'Edit Category' ),
                        'update_item' => __( 'Update Category' ),
                        'add_new_item' => __( 'Add New Category' ),
                        'new_item_name' => __( 'New Category Name' ),
                        'menu_name' => __( 'Categories' )
                      );
                      register_taxonomy($this->pluginSlugCategoryTaxonomy,array($this->pluginSlug), array(
                        'hierarchical' => true,
                        'labels' => $labels,
                        'show_ui' => true,
                        'show_admin_column' => true,
                        'query_var' => true,
                        'rewrite' => array( 'slug' => ''.$sel_category_parent['post_name'].'','hierarchical'=>true )
                      ));
                }

which all works fine and in turn prints "WPPizza Categories" in the admin as title when editing/adding categories related to the wppizza cpt. So far so good.

problem is as follows:

when i go to a "normal category" (i.e http://www.domain.com/category/uncategorized/) the title tag looks like this (which is fine)

            <title>Uncategorized | sitetitle</title>

however, when i go to the custom post type/taxonomy like so http://www.domain.com/wppizza_menu/desserts/ (permalink) or just http://www.domain.com/?wppizza_menu=desserts , the title tag looks like this

            <title>Desserts | WPPizza Categories | sitetitle</title>

when - what i would like it to read is

                <title>Desserts | sitetitle</title>     

in short, how do i get rid of "WPPizza Categories" in the title tag in the frontend ?

hope the above makes sense. happy to provide more code if required of course

0

I believe that WPPizza Categories is coming from

'name' => _x( 'WPPizza Categories', 'taxonomy general name' )

And your url problem is coming from not setting a slug. For example:

'rewrite'   => array( 'slug' => 'pizza_categories', 'with_front' => false ),

You need to replace the slug with something else, as you need something in place of 'wppizza_menu' in the url. You can change the title in your page template if you just want to remove 'WPPizza Categories', otherwise change the general name and it should propagate to the title tag.

I'd recommend using a regex and get_the_title(); if you want to remove the taxonomy name completely.

2
  • Hi, thanks for taking the time. Generally speaking though, it's not a url/slug problem (the slug can be set dynamically to whatever) its a title TAG problem between <head> and </head> where it uses the taxonomy general name – olly Dec 20 '13 at 11:52
  • 1
    hmm, the best/only solution in can come up with at the moment is something like using this filter add_filter( 'wp_title', 'custom_title', 20 ); but it strikes me as odd that it gets inserted into the title tag to start off with if "normal" post categories don't behave that way – olly Dec 20 '13 at 12:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.