This plugins enables the primary category selection option for woo which had surprisingly dissappeared for many people . But the issue is that the breadcrumbs dont recognize it on the front end.
]]>As I’m imagining this plugin is really only used by other developers, here’s some sample code I’m using that is hooking into Google Analytics, and outputting the category or “primary category” as an additional parameter to be viewed under the page_view event.
the part you might find helpful is
// get the term object for the primary category and assign it to our variable
$primary_category_id = get_post_meta( $post_id, 'epc_primary_category', true );
$postCategory = get_term( $primary_category_id )->name;
This is what I place in our single.php template for blog posts.
<?php
$categories = get_the_category();
$category_names = array();
foreach ($categories as $category) {
$category_names[] = $category->name;
}
$postCategory = implode(', ', $category_names);
// run only if the post has a designated primary category, which is done through the Easy Primary Category plugin
if ( get_post_meta( $post_id, 'epc_primary_category', true ) ) {
// get the term object for the primary category and assign it to our variable
$primary_category_id = get_post_meta( $post_id, 'epc_primary_category', true );
$postCategory = get_term( $primary_category_id )->name;
}
?>
<script>
const postCategory = '<?php echo $categories_string; ?>';
// if the current page starts with /blog/ but isn't the blog index page, then look for the javascript variable postCategory and send that to GA4
if(currentPath.startsWith('/blog/') && currentPath !== '/blog/'){
if(typeof postCategories !== 'undefined'){
// send event to GA4
gtag('event', 'page_view', {
'blog_category': postCategories
});
}
}
</script>
]]>
Hello, its an interesting plugin, just curious if it still works, I see that no updates have been made to it in years…I would just ask if thats because it doesnt need to be updated or there is some issue..thanks-
]]>Hello, I am using your plugin and I want to get the primary category name.
I am using this code on my website:
<?php $categories = get_the_category(); if ( ! empty( $categories ) ) { echo esc_html( $categories[0]->name ); } ?>
Thanks very much !
]]>Is it possible?
]]>epc-taxonomy-metabox.min.js conflicts with Yoast SEO plugin in admin, prevents render of Yoast SEO content optimization fields.
This function call seems to be the source of the conflict in epc-taxonomy-metabox.js (line 226):
$( _.values( taxonomies ) ).initYstSEOPrimaryCategory();
I love your plugin and I started to use inside one of my latest projects. Since I just enabled Gutenberg I noticed your plugin stoped to work.
Do you have any plans to fix it?
]]>$categories = get_the_category();
$category_id = $categories[0]->cat_ID;
The above will give me the first category, but that’s not always the one I have marked as primary.
How can I get the primary category on a single post (if that post is assigned to more than one category)?
]]>I used to use Yoast for Primary Catagories, but we have recently moved away from Yoast and found your plugin. We are trying to see if it would be possible to display what the primary category is and ensure it has a link to the category archive.
Thanks for all the help
]]>Hi,
This is a plugin that I have been looking for a very long time.
Tries this and was able to select a subcategory as primary however the breadcrumb on that product page did not change. Is there something else I would need to do to update the breadcrumb.
Thanks
]]>