-
AuthorPosts
-
February 22, 2021 at 9:13 am #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.February 22, 2021 at 6:52 pm #1282866Hey Hugh,
Yes, you can copy this function to your child theme and re-write it completely.
Best regards,
VictoriaFebruary 23, 2021 at 6:06 am #1282965Hey 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)February 23, 2021 at 6:35 am #1282974Hi Gal,
Please use this hook to change how it works: avia_breadcrumbs
Hope this helps.Best regards,
NikkoFebruary 23, 2021 at 8:36 am #1282994And 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()
usingfunction_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.February 24, 2021 at 7:57 am #1283309Hi supporthealthclinic,
I see, we’ll request that to our devs.
For now, just modify the avia_breadcrumbs function in the parent theme.Best regards,
NikkoFebruary 25, 2021 at 6:33 pm #1283729Hi,
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ünterFebruary 26, 2021 at 3:37 am #1283772Hi 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,
GalFebruary 27, 2021 at 11:43 am #1284086Hi,
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ünterFebruary 28, 2021 at 5:26 am #1284195Hi Günter,
Sorry, I interpreted “shortcut” as “shortcode“. Calling the filter “avf_breadcrumbs_output” or “avf_breadcrumbs_external” may be clearer.
Cheers,
GalFebruary 28, 2021 at 4:58 pm #1284266 -
AuthorPosts
- The topic ‘Completely replace breadcrumbs’ is closed to new replies.