Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #1282735

    I’ve used the ‘avia_breadcrumbs’ filter to overwrite the theme’s breadcrumbs with those of Rank Math SEO, but this seems like a waste, because on every page load, breadcrumbs are basically computed twice.

    Is there a way to completely replace the call to avia_breadcrumbs() with a call to another function?

    If so, how do I do it?

    If not, there should be. Wrapping the function with if ( function_exists or running it as a filter or an action are all good ways of doing this.

    #1282866

    Hey Hugh,

    Yes, you can copy this function to your child theme and re-write it completely.

    Best regards,
    Victoria

    #1282965

    Hey Victoria,

    That produces the following (which I expected):

    PHP Fatal error: Cannot redeclare avia_breadcrumbs() (previously declared in /home2/supporthealth/public_html/wp-content/themes/enfold-child/functions.php:238) in /home2/supporthealth/public_html/wp-content/themes/enfold/framework/php/class-breadcrumb.php on line 175

    Regards,
    Gal (on behalf of Hugh)

    #1282974

    Hi Gal,

    Please use this hook to change how it works: avia_breadcrumbs
    Hope this helps.

    Best regards,
    Nikko

    #1282994

    And we’re back to square 1.

    I’m already using the hook, but it basically just doubles the work. I throw away everything and start over, and that’s just a waste.

    Please allow complete replacement of the function avia_breadcrumbs() using function_exists() or provide some other way to use a different function for breadcrumb generation, e.g. by using an action hook that can be unhooked.

    #1283309

    Hi supporthealthclinic,

    I see, we’ll request that to our devs.
    For now, just modify the avia_breadcrumbs function in the parent theme.

    Best regards,
    Nikko

    #1283729

    Hi,

    I added a filter for the next release at the beginning of the function:

    
    function avia_breadcrumbs( $args = array() ) 
    {
    	global $wp_query, $wp_rewrite;
    
    	/**
    	 * Allow to shortcut breadcrumb trail. Return anything then false to shortcut.
    	 * 
    	 * @since 4.8
    	 * @param boolean $value
    	 * @param array $args
    	 * @return string|false
    	 */
    	$breadcrumb_shortcut = apply_filters( 'avf_breadcrumbs_shortcut', false, $args );
    	if( false !== $breadcrumb_shortcut )
    	{
    		return $breadcrumb_shortcut;
    	}
    
    ........
    
    
    

    This is more flexible in case we move this function in a class.

    Best regards,
    Günter

    #1283772

    Hi Günter,

    How would I use this filter? I’m not using a shortcut. I’m using a function.

    Perhaps you can use if ( ! empty( $args['output'] ) ) return $args['output'] ;. This way, I can use the argument filter to add the output to the arguments. Seems cleaner and uses existing filters.

    What do you think?

    Cheers,
    Gal

    #1284086

    Hi,

    In this filter you can call your function and return your result string or an empty string (if you do not like a breadcrumb or handle output by yourself).
    If you return boolean false, than our logic will proceed.

    You can use any logic inside the filter you need to decide what to do.

    The frame would look like (put e.g. in functions.php of your child theme):

    
    function my_breadcrumbs_shortcut( $breadcrumb, $args )
    {
    	$breadcrumb = your_breadcrumb_function( $args );
    	
    	return $breadcrumb;
    }
    
    add_filter( 'avf_breadcrumbs_shortcut', 'my_breadcrumbs_shortcut', 10, 2 );
    

    If you need more help with using or adding the filter let us know and we can add it for you.

    Best regards,
    Günter

    #1284195

    Hi Günter,

    Sorry, I interpreted “shortcut” as “shortcode“. Calling the filter “avf_breadcrumbs_output” or “avf_breadcrumbs_external” may be clearer.

    Cheers,
    Gal

    #1284266

    Hi,

    Thanks for this feedback, I changed it to avf_breadcrumbs_external.

    Best regards,
    Günter

Viewing 11 posts - 1 through 11 (of 11 total)
  • The topic ‘Completely replace breadcrumbs’ is closed to new replies.