• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

How to limit a shortcode to only appear for certain categories of posts

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › How to limit a shortcode to only appear for certain categories of posts

This topic is: not resolved
  • This topic has 5 replies, 4 voices, and was last updated 2 years, 8 months ago by fazmusiciha.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • July 11, 2020 at 1:07 pm #500082
    Bruce Rawles
    Participant

    Does anyone have any suggestions how to have a shortcode (in this case [DISPLAY_ULTIMATE_SOCIAL_ICONS] which you can see manually inserted at the top of this post: https://yachatsnews.com/yachats-council-forgives-11000-of-19000-utility-bill-for-low-income-apartment-developer-after-massive-water-leak-in-february/ ) appear ONLY on posts with certain categories? My client would like to exclude a few of the current 16 post categories from showing the social sharing icons. I'm familiar with using the display: none CSS property to selectively hide items with a class or id as a target, but not sure how this might work without having to copy and paste the shortcode (or not) on dozens of monthly posts – the current tedious and not-at-all elegant workaround. Many thanks in advance for any suggestions! 🙂

    July 11, 2020 at 3:50 pm #500087
    Anita
    Keymaster

    If you using the Ultimate Social Icons plugin, that's a better question for them. They may not have included that functionality within the theme. Check their support page - https://wordpress.org/plugins/ultimate-social-media-icons/.


    Love coffee, chocolate and my Bella!

    July 11, 2020 at 4:36 pm #500088
    andytc
    Participant

    If your comfortable adding code to functions.php in the childtheme , you could try this. Just change the category ID's to match your own needs. This will show the icons only on single posts in those categories.

    /*********************************
    *
    *  Custom Social Icons
    *
    *********************************/
    
    // priority '5' added to be above main content
    add_action( 'genesis_entry_content', 'custom_social_icons' , 5 ); 
    
    function custom_social_icons() { 
        // add comma seperated list of category id's to show social icons on single posts only
        if ( is_single() && in_category ( array( 7, 8, 3 ) ) )  { 
          
          echo do_shortcode( '[DISPLAY_ULTIMATE_SOCIAL_ICONS]' );
    
        } 
    }
    July 14, 2020 at 8:23 am #500115
    Bruce Rawles
    Participant

    THANKS AndyTC, that works like a charm; exactly what I was looking for and much appreciated! Thanks also, Anita for your suggestion; that was my backup plan. What a great support community; so grateful to you both ... and all! 🙂

    July 14, 2020 at 9:45 am #500116
    andytc
    Participant

    That’s fantastic Bruce , glad it’s all working.

    July 20, 2020 at 6:01 am #500199
    fazmusiciha
    Member

    THANKS AndyTC, that works


    دانلود آهنگ جدید سایت FazMusic

  • Author
    Posts
Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble