WordPress.org

Ready to get started?Download WordPress

Forums

Breadcrumb NavXT
[resolved] How can I maintain compatibility between Breadcrumb NavXT and qTranslate? (9 posts)

  1. weeix
    Member
    Posted 1 year ago #

    Hello,

    I'm using Breadcrumb NavXT 4.2 with qTranslate 2.5.32

    My previous problem is about the Home link in the breadcrumb that keeps reverting back to default language when clicked (e.g. when I switched to Thai language I expect the home link to be mysite.com/th, not mysite.com)

    I temporary fixed above problem by editing breadcrumb_navxt_class.php in your plugin directory:

    1/4 line 732

    $breadcrumb->set_url(get_home_url());

    to

    $breadcrumb->set_url(function_exists(qtrans_convertURL) ? qtrans_convertURL(get_home_url()) : get_home_url());

    2/4 line 738

    $breadcrumb = $this->add(new bcn_breadcrumb($this->opt['Smainsite_title'], $this->opt['Hmainsite_template'], array('mainsite-home'), get_home_url($current_site->blog_id)));

    to

    $breadcrumb = $this->add(new bcn_breadcrumb($this->opt['Smainsite_title'], $this->opt['Hmainsite_template'], array('mainsite-home'), function_exists(qtrans_convertURL) ? qtrans_convertURL(get_home_url($current_site->blog_id)) : get_home_url($current_site->blog_id)));

    3/4 line 753

    $breadcrumb = $this->add(new bcn_breadcrumb($this->opt['Shome_title'], $this->opt['Hhome_template'], array('site-home'), get_home_url()));

    to

    $breadcrumb = $this->add(new bcn_breadcrumb($this->opt['Shome_title'], $this->opt['Hhome_template'], array('site-home'), function_exists(qtrans_convertURL) ? qtrans_convertURL(get_home_url()) : get_home_url()));

    and 4/4 line 758

    $breadcrumb = $this->add(new bcn_breadcrumb($this->opt['Smainsite_title'], $this->opt['Hmainsite_template'], array('mainsite-home'), get_home_url($current_site->blog_id)));

    to

    $breadcrumb = $this->add(new bcn_breadcrumb($this->opt['Smainsite_title'], $this->opt['Hmainsite_template'], array('mainsite-home'), function_exists(qtrans_convertURL) ? qtrans_convertURL(get_home_url($current_site->blog_id)) : get_home_url($current_site->blog_id)));

    But these fixes would definitely break when the Breadcrumb NavXT is updated.

    Can you please give me some advice on how to maintain this compatibility?

    Thanks

    edit: I can't use strong in code tag to highlight the changed code, so I used blockquote tag instead.

  2. b-tag
    Member
    Posted 1 year ago #

    Hi,

    I have encountered the same issue, and I think I found a shorter solution. What applies to my case however, might not completely apply to yours since I am using a non-multisite WP install, but hey, it's a start.

    First, alter only two lines in breadcrumb_navxt_class.php:

    Change ln. 31 to:

    public $linked;

    as well as ln. 33 to:

    public $url;

    These changes are insignificant, and I believe the plug-in author could incorporate them easily in the subsequent versions of the plug-in.

    Second, create a function in your theme's functions.php like:

    function mytheme_trail($breadcrumbs) {
    
    	if ($breadcrumbs->opt['bhome_display']) {
    
    		$key = array_pop(array_keys($breadcrumbs->trail));
    		$breadcrumb = $breadcrumbs->trail[$key];
    
    		if (!empty($breadcrumb->linked)) {
    
    			$breadcrumb->set_url(qtrans_convertURL(get_home_url()));
    			$breadcrumbs->trail[$key] = $breadcrumb;
    		}
    	}
    }

    and hook it to the following action:

    add_action('bcn_after_fill', 'mytheme_trail');

    This function will rewrite the URL of the home link of the trail, as provided by qTranslate.

    Hope this helps,

    b.

  3. John Havlik
    Member
    Plugin Author

    Posted 1 year ago #

    b-tag has the correct idea for doing this, at the moment. It will be slightly easier in the future when I add a new filter to bcn_breadcrumb::set_url(), then you'll be able to slip qtrans_convertURL() right in. E.g. in the future (next release) the following will be valid:

    function my_bnc_qtrans_url_filter($url)
    {
    	return qtrans_convertURL($url);
    }

    and hook it with:
    add_filter('bcn_breadcrumb_url', 'my_bnc_qtrans_url_filter');

  4. weeix
    Member
    Posted 1 year ago #

    mtekk, may I ask you a few more questions?

    1. Can I prepare your code in my theme before the next release?
    2. Would it be nice if I ask Mr.Qian to include this hook in his plugin when your filter is ready?

    Thank you, both of you.

  5. John Havlik
    Member
    Plugin Author

    Posted 1 year ago #

    Yes, you may do both.

  6. alezander
    Member
    Posted 1 year ago #

    Hello mtekk

    When do you plan to fix the problem with breadcrumb ?

  7. alezander
    Member
    Posted 1 year ago #

    Hello b-tag

    In my breadcrumb_navxt_class.php
    line 31 is
    public $linked;

    and line 33 is
    public $url;

    I have not changed anything in this file.

    Just added to my theme's functions.php your code.
    The problem was not solved.

  8. John Havlik
    Member
    Plugin Author

    Posted 1 year ago #

    You should be able to do what I said to do in the above reply and that *should* work with Breadcrumb NavXT 4.3. As for "fixing" this in Breadcrumb NavXT, the way I see it this is a 3rd/4th party plugin issue. Frankly, I'm not keen on adding custom code to support other plugins directly into Breadcrumb NavXT. This is rather simple for end users that need it to implement in a site specific plugin, or functions.php.

  9. alezander
    Member
    Posted 1 year ago #

    The solution proposed by weeix works. Thanks

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic