• 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

Use this Genesis function with conditional statements for multisite?

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 › Use this Genesis function with conditional statements for multisite?

This topic is: not resolved

Tagged: genesis_search_text, Search Form

  • This topic has 7 replies, 3 voices, and was last updated 3 years, 6 months ago by ilkweb.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • July 5, 2019 at 6:50 am #492136
    ilkweb
    Member

    Hi there,

    I purchased the Prop Plus package and am working with the Business Pro theme.

    I added a search box to my nav bar and used the following function in functions.php to alter the placeholder text shown to site visitors:

     //* Customize search form input box text
    add_filter( 'genesis_search_text', 'sp_search_text' );
    function sp_search_text( $text ) {
    	return esc_attr( 'Search website' );
    }

    My question is whether or not this function can be altered so that different placeholder text is shown on a different page and all its subpages?

    Example

    http://www.example.com/en/ and all subpages shows the placeholder text 'Search'.

    while

    http://www.example.com/fr/ and all subpages shows the placeholder text 'Chercher'

    For better context, I'm creating a multi-site, and I think I might be better off putting either function in its own plugin activated for both the /en/ and /fr/ site.

    Is it possible to easily create a plugin for Genesis themes instead of using the one functions file in the child theme folder?

    http:///localhost/
    July 5, 2019 at 11:10 am #492141
    andytc
    Participant

    You could use is_tree for parent/child pages

    Add this code to functions first -

    // If is tree parent/child pages
    function is_tree($pid) {   
        global $post;         
        if(is_page()&&($post->post_parent==$pid||is_page($pid))) 
            return true;     
          else 
            return false;  
    };

    And then find the parent page ID's you want to target and add this code to functions.php

    Example -

    if (is_tree(2)) { // '2' is the parent page ID - change to your ID
       
    	//* Customize search form input box text
    	add_filter( 'genesis_search_text', 'sp_search_text' );
    	function sp_search_text( $text ) {
    		return esc_attr( 'Search website' );
    	}
    
    }

    Then just add the other pages you want to target in the same way

    if (is_tree(151)) { // '151' is the parent page ID - change to your ID
       
    	//* Customize search form input box text
    	add_filter( 'genesis_search_text', 'sp_search_text' );
    	function sp_search_text( $text ) {
    		return esc_attr( 'Search' );
    	}
    
    }

    https://css-tricks.com/snippets/wordpress/if-page-is-parent-or-child/

    July 5, 2019 at 1:47 pm #492146
    ilkweb
    Member

    Thanks so much for the reply! The pages I am going to be targeting are actually the homepages of each website in the multisite installation. So /en/ and /fr/ are not actually WordPress pages.

    Even so, would this work? http://www.example.com/en/ would be the top level domain, and therefore count as the homepage.

    I doubt the following would work, so I'm eliminating it as a possibility:

    if (is_tree(en)) { // 'en' is the parent page ID - change to your ID
       
    	//* Customize search form input box text
    	add_filter( 'genesis_search_text', 'sp_search_text' );
    	function sp_search_text( $text ) {
    		return esc_attr( 'Search' );
    	}
    
    }

    My other option is to use the plugin approach and place my function in each site. I'm still curious to know what my options are here so I'd be interested to carry on debating it!

    Thanks again for the reply.

    July 5, 2019 at 4:03 pm #492148
    andytc
    Participant

    No that won’t work for you , it’s only for parent/child pages that are correctly arranged in WordPress. For example you’d have a parent page called ‘About Us’ and child pages under that, is_tree will target the parent and all the pages under it , so it’s useful for things like custom sidebars for specific areas of the site that need to appear on all the children.

    July 5, 2019 at 11:29 pm #492150
    Brad Dalton
    Participant

    Link to the live English and French sub pages please.

    1. You could use a ternary like this :

    add_filter( 'genesis_search_text', 'conditional_search_text' );
    function conditional_search_text( $text ) {
    
        $fr = esc_attr( 'Chercher' );
        $en = esc_attr( 'Search' );
    
        $output = Your Condition ? $fr : $en;
    
        return $output;
    }
    

    Swap out Your Condition in the above code.

    2. Otherwise, you can use if else statements like this example :

    add_filter( 'genesis_search_text', 'conditional_search_text' );
    function conditional_search_text( $text ) {
    
        $fr = esc_attr( 'Chercher' );
        $en = esc_attr( 'Search' );
    
        if (condition) {
            return $fr;
        } else {
            return $en;
        }
    }
    

    Make sure you add the correct condition which i won't know until i see your live pages.


    Get Help – Book Consultation.

    July 6, 2019 at 3:45 am #492157
    ilkweb
    Member

    Hi Brad,

    Thanks for the suggestions! I'm developing in a local host, so I cannot provide links.

    I'm aware of other conditions pertaining to multisite installs: https://codex.wordpress.org/Conditional_Tags#Part_of_a_Network_.28Multisite.29

    July 6, 2019 at 3:59 am #492158
    ilkweb
    Member

    No that won’t work for you , it’s only for parent/child pages that are correctly arranged in WordPress. For example you’d have a parent page called ‘About Us’ and child pages under that, is_tree will target the parent and all the pages under it , so it’s useful for things like custom sidebars for specific areas of the site that need to appear on all the children.

    I wonder how functions.php will look at a multisite install though. Perhaps this could work? I'm using one functions.php file in a single child theme, and am running two websites with one WordPress multisite network.

    July 6, 2019 at 4:32 am #492159
    ilkweb
    Member

    Make sure you add the correct condition which i won't know until i see your live pages.

    I've found a question similar to mine in which get_current_blog_id() is cited as the solution: https://wordpress.stackexchange.com/questions/283995/how-do-i-nest-conditionals-to-identify-sub-site-other-criteria

    I've identified the blog urls as follows:

    Blog ID = 1 (www.example.com/) using search box text 'Search'
    Blog ID = 2 (www.example.com/en/) using search box text 'Search'
    Blog ID = 3 (www.example.com/fr/) using search box text 'Chercher'

  • Author
    Posts
Viewing 8 posts - 1 through 8 (of 8 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