• 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

Added one filter, it worked; added two, it broke the site. Why?

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 › Added one filter, it worked; added two, it broke the site. Why?

This topic is: resolved

Tagged: add filter, genesis_attr_content

  • This topic has 6 replies, 4 voices, and was last updated 3 years, 4 months ago by Yumei.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • January 9, 2019 at 9:34 am #235608
    Yumei
    Participant

    I found some code here to add an extra class ("team-title"). The code worked:

    function wpstudio_add_class( $attributes ) {
    	$attributes['class'] = $attributes['class']. 'team_title';
    	  return $attributes;
      }
      add_filter( 'genesis_attr_content', 'wpstudio_add_class' );

    I wanted to add yet another class. But after I duplicated the same block of code, changing only the class name (to "team-subtitle"), the site broke:

    function wpstudio_add_class( $attributes ) {
    $attributes['class'] = $attributes['class']. 'team_title';
    return $attributes;
    }
    add_filter( 'genesis_attr_content', 'wpstudio_add_class' );

    function wpstudio_add_class( $attributes ) {
    	$attributes['class'] = $attributes['class']. 'team_subtitle';
    	  return $attributes;
      }
      add_filter( 'genesis_attr_content', 'wpstudio_add_class' );

    Why is that?

    http://yumeil.sgedu.site/aai2/our-team/
    January 9, 2019 at 11:58 am #236729
    Victor Font
    Moderator

    Functions have to have unique names. You have two function named wpstudio_add_class


    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    January 9, 2019 at 2:14 pm #237851
    Yumei
    Participant

    Got it! Thanks!

    January 9, 2019 at 2:58 pm #238190
    Yumei
    Participant

    Maybe I replied too soon:

    So I give the second function a different (unique) name. The site doesn't go blank, but the code doesn't seem to have any effect. So is this related to PHP syntax? Is this unique to Genesis's hooks? Or is this WordPress specific?

    Need some pointers so I try to figure it out.

    January 9, 2019 at 6:36 pm #239908
    Brad Dalton
    Participant

    Only use 1 filter function to add both custom classes.


    2700 Genesis Tutorials

    January 9, 2019 at 10:21 pm #241709
    andytc
    Participant

    Try this -

    function wpstudio_add_class( $attributes ) {
    	$attributes['class'] = $attributes['class']. ' team_title team_subtitle';
    	  return $attributes;
      }
      add_filter( 'genesis_attr_content', 'wpstudio_add_class' );

    Note - As victor mentioned - there are 2 instances of the function name to change -

    function wpstudio_add_class

    and also at the end -

    add_filter( 'genesis_attr_content', 'wpstudio_add_class' )

    They must be the same

    January 10, 2019 at 11:31 am #247991
    Yumei
    Participant

    @andytc Thank you! I learned something that would have taken me a long time to get right.

  • Author
    Posts
Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘Added one filter, it worked; added two, it broke the site. Why?’ is closed to new replies.

CTA

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

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2022 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