• The plugin loads the wrong title, but good link of Root page in custom post type.
    I corrected this by changing the function do_root in class.bcn_breadcrumb_trail.php

    	/**
    	 * A Breadcrumb Trail Filling Function 
    	 *
    	 * Handles only the root page stuff for post types, including the "page for posts"
    	 * 
    	 * @param string $type_str The type string variable
    	 * @param int $root_id The ID for the post type root
    	 * @param bool $is_paged Whether or not the current resource is on a page other than page 1
    	 * @param bool $is_current_item Whether or not the breadcrumb being generated is the current item
    	 */
    	protected function do_root($type_str, $root_id, $is_paged = false, $is_current_item = true)
    	{
    		//Nothing to do for the page post type, exit early
    		if($type_str === 'page')
    		{
    			return;
    		}
    		$frontpage_id = get_option('page_on_front');
    		//Retrieve the post for the root_id as we will need it eventually
    		$bcn_post = get_post($root_id);
    		//We'll have to check if this ID is valid, e.g. user has specified a posts page
    		if($bcn_post instanceof WP_Post && $root_id > 0 && $root_id != $frontpage_id)
    		{
    			if ( defined('ICL_LANGUAGE_CODE') && function_exists('icl_object_id') ) {
                    $current_id = icl_object_id( $root_id, get_post_type( $root_id ), true, ICL_LANGUAGE_CODE );
                    $titlewpml = get_the_title($current_id);
                }else{
                    $titlewpml = get_the_title($root_id);
                }
    			//Place the breadcrumb in the trail, uses the constructor to set the title, template, and type, we get a pointer to it in return
    			$breadcrumb = $this->add(new bcn_breadcrumb($titlewpml, $this->opt['Hpost_' . $type_str . '_template_no_anchor'], array($type_str . '-root', 'post', 'post-' . $type_str), null, $root_id));
    			//If we are at home, or any root page archive then we need to add the current item type
    			if($is_current_item)
    			{
    				$breadcrumb->add_type('current-item');
    			}
    			//If we're not on the current item we need to setup the anchor
    			if(!$is_current_item || ($is_current_item && $this->opt['bcurrent_item_linked']) || ($is_paged && $this->opt['bpaged_display']))
    			{
    				$breadcrumb->set_template($this->opt['Hpost_' . $type_str . '_template']);
    				//Figure out the anchor for home page
    				$breadcrumb->set_url(get_permalink($root_id));
    			}
    			//Done with the "root", now on to the parents
    			//If there is a parent post let's find it
    			if($bcn_post->post_parent > 0 && $bcn_post->ID != $bcn_post->post_parent && $frontpage_id != $bcn_post->post_parent)
    			{
    				$this->post_parents($bcn_post->post_parent, $frontpage_id);
    			}
    		}
    	}

    But I know that this is not a good solution and I will lose changes when updating.
    How to fix this error without interfering with the plugin files?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author John Havlik

    (@mtekk)

    Enhanced compatibility with WPML is available with the Breadcrumb NavXT WPML Extensions plugin. Your other option is to write an action that translates the root page IDs for CPTs in the Breadcrumb NavXT options just before filling the breadcrumb trail (place this action in a site-specific plugin). Either option is better than modifying the core plugin.

    Thread Starter djsidor

    (@djsidor)

    Do you think it could be that way?

    if ( function_exists('bcn_display') && !is_front_page() ) {
    add_filter('the_title', 'breadcrumbs_wpml_title' );
    bcn_display();
    remove_filter('the_title', 'breadcrumbs_wpml_title' );
    }
    function breadcrumbs_wpml_title($title, $id){
        if ( defined('ICL_LANGUAGE_CODE') && function_exists('icl_object_id')) {
            $page = get_page_by_title( $title);
            $current_id = icl_object_id( $page->ID, get_post_type( $page->ID ), true, ICL_LANGUAGE_CODE );
            $pagecurrentlang = get_post($current_id);
            return $pagecurrentlang->post_title;
        }else{
             return $title;    
        }
    }

    It works for me and does not interfere with the plugin files

    Plugin Author John Havlik

    (@mtekk)

    If it works for you, you can do it that way. You may find the filter bcn_breadcrumb_title a better solution that the_title.

    goldorak

    (@goldorak)

    Hi John,

    Would it be possible to include this change from @djsidor into the next Breadcrumb NavXT update? Or would it be necessary to purchase the other plugin?

    It is working great for me and no other changes are needed to my WordPress bilingual website.

    Plugin Author John Havlik

    (@mtekk)

    My general philosophy is that support for features not in WordPress core (e.g. 3rd party plugins) is handled via extension plugins to Breadcrumb NavXT. You can use what posted above, just note that it uses WPML’s old API.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘WPML Root page title’ is closed to new replies.