[Resolved] Shortcodes for categories showing on posts under categories in header element

Home Forums Support [Resolved] Shortcodes for categories showing on posts under categories in header element

Home Forums Support Shortcodes for categories showing on posts under categories in header element

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1408004
    William

    Hi there,

    If there is a shortcode for a category, is there a way to make the shortcode for the appear for all posts that contain in the header element, for that category?

    Kind regards,

    Will

    #1408122
    Leo
    Staff
    Customer Support
    #1409219
    William

    I don’t think so – the shortcode I made using ACF called ‘author_info’ – the content for this field is filled in on the category page:

    I want to display such a shortcode in the header element for all posts under that category.

    Kind regards,

    Will

    #1409338
    David
    Staff
    Customer Support

    Hi there,

    i provided you with the method to do that here for the Category Info:

    https://generatepress.com/forums/topic/custom-field-not-working-for-category-archive-pages/#post-1345726

    The same principles apply here simply change the shortcode name and the get_field to whatever you set up in ACF.

    #1410193
    William

    Hi there,
    Thanks for this but it does not seem to provide the right functionality.

    On such a post page, if I add the shortcode [category_summary] or [category_image], to the post header element, nothing shows.

    The [category_summary] and [category_image] can be see on this category page. I would like to add these to post header elements and show if they are under the same category.

    Kind regards,

    Will

    #1410268
    David
    Staff
    Customer Support

    As much as we like to help where we can building ACF code is out of our scope.
    Best to ask on ACF support on how to get the current posts category description.

    #1410805
    William

    Okay thanks anyway

    #1410898
    David
    Staff
    Customer Support

    ACF support is really good – they should be able to help quickly.

    #1410966
    William

    Hi there,

    I’ve just managed to muster something together for this, so thought to share with you and the community as others might find it useful.

    add_shortcode( 'shortcode_name', function() {
    	
        $categories= get_the_category();
    
        $term = get_category($categories[0]->term_id);
        
        $shortcode_name= get_field('shortcode_name', $term);
    
        return $shortcode_name;
    	
    } );

    Where replacing ‘shortcode_name’ for the custom field of the category will allow you to add the shortcode into the post as [shortcode_name].

    Kind regards,

    Will

    #1411234
    David
    Staff
    Customer Support

    Awesome – thanks for sharing 🙂

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.