So I have this Yoast snippet that lets us use Yoast SEO breadcrumbs on our wordpress website. By placing this snippet on any of the pages or header.php it will list the breadcrumb menu for our site.
<?php
if ( function_exists('yoast_breadcrumb') ) {
yoast_breadcrumb('
<p id="breadcrumbs">','</p>
');
}
?>
However instead of placing it on individual pages or in the header.php I would like it to appear after every div with the id of #primary
. For example my site has a primary div for the main content and a secondary div for the sidebar. I want it at the top of every content page.
Question: I am wondering if there is a simple snippet I can place in my functions.php that will add the above code after every div with the id of #primary
As I feel this would be cleaner than finding all the #primary divs and placing the code over and over on every specific page.
Thanks for any help!
Doing it properly would require knowing the theme structure, since you'd just put it in the correct template file where you want it to go, but you can insert it via Javascript on all pages by putting this in your footer.php:
<?php if ( function_exists('yoast_breadcrumb') ): ?>
<script>
jQuery(function($) {
$('#primary').prepend('<?php yoast_breadcrumb('<p id="breadcrumbs">','</p>');?>');
});
</script>
<?php endif; ?>