Wordpress Yoast Get Primary Category
You can then use get_term to get the WP_Term object. If class_exists WPSEO_Primary_Term Show the posts Primary category if this Yoast feature is available one is set.
The Following Post Will Hopefully Give Both Newbies And Veteran Bloggers Some New And Helpful Information About Using I Wordpress Help Blog Help Blog Traffic
There is a small bug that I am hoping can be easily fixedits to do with the Category tag system for blo.

Wordpress yoast get primary category. Get the categories for the post. Loop through each cat foreach categories as category. If post has a category assigned.
And to add to that you want that Category to be linked. If category category_display. The below code worked for me to get the primary category that is set up in the admin section primary_cat_idget_post_metaproduct-id_yoast_wpseo_primary_product_cattrue.
Wrapper to hide any errors from top level categories or products without category if categories. When you have a list of posts you might need to show only one category for this post. SHOW YOAST PRIMARY CATEGORY OR FIRST CATEGORY category get_the_category.
Checks for a yoast primary category if it exists move the category to the first position in the categories array. Now on the right side click on the Publish button to generate the product feed. Is_wp_error category.
To make it reusable place the function in your functionsphp or more preferably in a custom plugin. To find the Yoast SEO primary category feature in WordPress go to the Document tab in the sidebar and then to the Categories tab. A post may be under multiple categories such as News and Recent work.
So in your WordPress loop you want to display WooCommerce Products with only the Primary Product Category displayed. Ive read and understood the contribution guidelines. Select your categories and use the dropdown menu below them to se the primary category.
To get the primary category in the theme I can just use the get_the_category-function like so. Set Primary category using the Yoast SEO plugin. Query new WP_Query cat X Just in case Yoast data corrupted post no longer attached to X term but primary meta remains meta_query key.
The Yoast SEO plugin now has a dedicated function yoast_get_primary_term_id for getting the primary terms ID. Heres a basic layout of what this function will do for us. Return array The category name slug and URL.
The item name is Flashlight and the Primary Category is Tools a link. Function set_primary_on_publish post_id global post. So to get this category you will need to place the following function in your functionsphp file.
Knowing this you can use a meta query to get all posts with primary category ID X. Select the primary category from the. Since Yoast handles selecting this primary category we can hook in and grab it without too much trouble.
Get the children if any of the current cat children get_categories. The primary category as is a feature of the Yoast SEO plugin is available in wp_postmeta table. For the Product Category attribute on the Value field scroll down and choose Yoast Primary Category.
Your product feed will be generated with the Yoast attributes using Product Feed Manager For WooCommerce. Ive searched for any related issues and avoided creating a duplicate issue. If two or more categories are selected you should see a drop down menu beneath the categories that says Select the primary category If you are not seeing this can you please confirm you are using the most recent Yoast v942 and WordPress version.
How to select a primary category Go to the Categories setting in the sidebar of the post editing screen. Use Yoast SEO Primary Category for Related WooCommerce Products. Under a post the make primary category function is still available.
The related query is cached in WordPress. Click on the dropdown menu under Select the primary category. UseCatLink true.
Primary_term_id yoast_get_primary_term_id taxonomy_slug post_id_or_object. Each posts primary category is set against meta_key value _yoast_wpseo_primary_category with meta_value having the term_id from the wp_terms table for the primary category. Function get_post_primary_category post_id termcategory return_all_categoriesfalse return array.
Will return false if no primary term has been set primary_term_id yoast_get_primary_term_id. Function get_primary_category post 0 if. How does selecting a primary category work.
Yoast Primary Product Category. Post post get_the_ID. Category_link.
Categories get_the_terms post-ID category. Yoast SEO stores the primary term ID as the post meta field _yoast_wpseo_primary_ taxonomy. This snippet was last updated on June 11 2019.
Getting The Primary Category from a WooCommerce product. The snippet below will alter the default WooCommerce products this will work with ANY theme so that they will display related items based on the Primary Category as marked by the function in the Yoast SEO Plugin. Gets the primary category set by Yoast SEO.
So whenever using it be sure to call the get_the_category function beforehand and then place the results in a variable which will be passed to the function.
Haroonpro I Will Do Wordpress Yoast Seo On Page Optimization Service For 20 On Fiverr Com Yoast Seo Seo Plugin Yoast
Ultimate Seo Checklist For E Commerce Companies Printable Checklist Semrush Marketingi Ecommerce Marketing Marketing Strategy Social Media Marketing Tips
How To Prevent Wordpress From Generating Image Sizes Wordpress Wordpress Tutorials Image
How To Use Wordpress Category Tag Pages For Seo Seo Wordpress Being Used
Yoast 3 1 Release Video Yoast Seo Seo Yoast
Ultimate Seo Checklist For E Commerce Companies Printable Checklist Ecommerce Marketing Marketing Strategy Social Media Marketing Tips
Hacked How To Get Back Into The Wordpress Admin Wordpress Admin Wordpress Tutorials Wordpress
Fix Yoast Seo Breadcrumb Not Including Categories In Genesis For Sub Categories Post Yoast Seo Cloud Computing Deep Learning
Learn How To Optimise Your Article For Maximum Search Traffic With 3 Seo Strategies That Work For Bloggers Squarespace Marketing Tips Blog Marketing Seo Tips
Why Yoast Seo Plugin Does Not Generate Xml Sitemap Asnowball Com Seo Plugin Yoast Seo Content Writing
Style Enews Subscribe Box Widgets Differently Genesis Platform Conditional Styling Code Subscribe Box Widget Subscribe
Yoast Google Analystics Google Analytics Wordpress Plugins Plugins
Seo For Beginners How To Optimize Your Blog Posts For Google Beautiful Dawn Designs Seo For Beginners Seo Yoast Seo
Yoast Google Analytics For Wordpress Plugin Yoast Wordpress Plugins Plugins Google Analytics
Why We Use Wordpress As Our Primary Contentmanagementsystem Cms Web Strategy Content Management System Wordpress
Here S What You Can Expect From Gutenberg Wordpress Wordpressupdate Develop Websitedesign Web Strategy Website Design Expectations
Fix Yoast Seo Breadcrumb Not Including Categories In Genesis For Sub Categories Post Yoast Seo How To Apply Seo Score
Yoast 3 1 Release Video Yoast Seo Seo Yoast
Post a Comment for "Wordpress Yoast Get Primary Category"