You can use get_the_category() and return the first result as in the example. Technically you could have several parent categories so you need to deal with this separately or expect that the first element of the array is always the right parent category.
Related Posts:
- Return HTML Template Page with PHP Function
- Change the filename format of saved featured images
- Getting the comment number relative to all the post’s comments
- How to use the php if statement [closed]
- lazy load comments wordpress on click
- Use Filename for Alt and Title Tags
- How to turn off redirection from ‘domain.com/login’ to ‘domain.com/wp-login.php’
- Trying to use Ternary operators with WP Conditionals
- How can one utilize a variable as a callback function name for add_settings_field
- Filter link to existing content suggestion
- How to strip non-alphanumeric characters, convert spaces to dashes, uppercase to lowercase in this context
- How to return multiples lines in a shortcode?
- wp_enqueue_style with style.php and WordPress functions
- Generate an array of parent/child page IDs, based on parent page name
- fallback image for featured image
- Add attribute / custom attribute to product in woocommerce
- Access/update database with jQuery
- Using a switch statement in WordPress
- wp_handle_upload – The uploaded file could not be moved to wp-content/uploads/2012/09
- How to create another version of my site based on the same database
- How to get bool with `get_option()` when already registered setting with type `boolean`
- Why is this Ajax not working?
- Pass PHP variable to JavaScript without inline JS
- Stumped on migration
- Count the number of times the search form template gets included on a page
- Displaying theme options in css
- Create a new usermeta field for users
- Where to edit the template that is generating the code for dynamic_sidebar left-sidebar in the Understrap theme? [closed]
- Append HTML Using Shortcode
- Get rid of this Strict Standards warning [closed]
- WordPress – Display array data of a child
- Image upload via FormData API and AJAX is not working ($_FILES always empty)
- I have a problem in the order of enqueues while enqueuing stylesheets and scripts for a specific page in my function.php
- Use DOMDocument with ob_start breaks my HTML code
- How to only enqueue script if it’s a post
- how to fix error “called incorrectly, should not be accessed directly”?
- trigger html cleanup for all posts
- get widget number from array dynamically
- How to auto fetch customer details in Woocommerce in checkout page
- Validation algorithm in checkout field
- Catchable fatal error: Object of class stdClass could not be converted to string after WP 4.7
- If has $title in widgets
- get href content [closed]
- Illegal string offset in PHP function
- Search WordPress using static html page
- Displaying text if post was within 5 hours
- Change “No Comments” link to “My String” on Blog Post (Find Snippet in Code or use CSS, PHP Solution) [closed]
- How to say if meta_value is greater than 0 in an array?
- Adding a tag_ID column into Categories inside the admin dashboard?
- How to get category name or ID by post?
- ACF Repeater Pagination stopped working since upgrade to php7.2
- Using featured image of blog archive page
- Best Way to Change a String in a WordPress Post
- Highlight the links without using dropdown
- Show get_sub_field value if it exists [closed]
- How to wrap every 3 posts in a div (and close the last div too) [closed]
- Dividing the loop to style post differently
- How to Display a List of Child Pages For a Parent Page in WordPress
- Why, when moving a WordPress multisite network, have my theme customisations stopped working?
- include content within conditional statement?
- How to change the author box selection on a post to a custom taxonomy
- How to send a php var to jQuery Ajax call with two different file
- User meta needed in query is serialized – how to unserialize safely?
- PHP calling AJAX function that relies on passed PHP function values not working
- Order by title Child Pages displayed in a Parent Page
- not outputting medium size image URL
- Help me I cannot link my font-awesome to my WordPress Theme. I have my font-awesome folder already in my project
- Adding new divs with custom classes to products on WooCommerce shop page [closed]
- Intermittent problem can the debug log give any clues?
- Echo short code syntax
- WordPress recent post
- Download Featured Image Link in Post Shortcode
- Show subcategory name selected in specific category woocoommerce
- Posts Per Page with a button to add more Posts
- How to get total gross revenue for current month in the woocommerce dashboard status widget
- Add custom attribute to product’s HTML to woocommerce cart page
- Change WooCommerce template for PDF – access to custom field
- Decoding an array in PHP (from the Shopify API) [closed]
- PHP is_embed error showing up
- How fix error in the WordPress loop?
- PHP Session Variable to WordPress Error
- Advanced WordPress SQL Query
- Run code before WordPress loads and insert data into WP if need be
- Editing existing pre-created menus in PHP
- need help to arabic text in wordpress
- Sorting Meta Fields?
- Themes with variable width or single columns? I want to display source code
- Category List in Theme Options Page
- Showing all post from all post type in admin backstage
- Or operators in PHP [closed]
- upload images on front by user using form
- how to iterate through xml data?
- Adding slides to an existing carousel manually
- What does this if-statement do?: if($pages=’ ‘) {}
- Really slow WordPress site [closed]
- $post->ID calls for current page, but what is the code to call for any new page created and published in WordPress?
- How to conditionally concatenate and translate two very long strings?
- How to limit the number of posts in the wordpress loop in conjunction with the “download more” button?
- seo meta description issue in google search
- WordPress Query – Blog Cards Duplicate issue