• 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

I can't filter nav menu items from this code

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 › I can't filter nav menu items from this code

This topic is: not resolved

Tagged: genesis_entry_header, ion icons, is_singular

  • This topic has 8 replies, 3 voices, and was last updated 5 years, 1 month ago by Erika.
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • April 11, 2017 at 5:37 pm #204643
    Erika
    Participant

    I'm trying to display an icon above my post titles, and the code below works, except that the icon also appears beside my nav menu links:

    //* Image above Title
    function new_title( $title ) {
    $new_title = '<i class="ion-fork"></i><br> ' . $title;
    return $new_title;
    }
    add_filter( 'the_title', 'new_title' );

    How do I filter out the nav menu items? I've tried a dozen different things and nothing works!

    http://demo.risenuponthee.com/ultimate-chef/2017/04/11/sample-post-with-headings/
    April 11, 2017 at 5:43 pm #204644
    carasmo
    Participant

    You would add a conditional that says: it's not admin and in the loop and a single page

    function new_title( $title ) {
    
    	if( ! is_admin() && in_the_loop() && is_singular()  ) {
    		$new_title = '<i class="ion-fork">x</i><br> ' . $title;
    		return $new_title;
    
    	}//end conditional
    	
    	return $title;
    }
    add_filter( 'the_title', 'new_title' );

    Genesis Theme Customization and Help

    April 11, 2017 at 5:44 pm #204645
    carasmo
    Participant

    if you want both archive and single, just remove the && is_singluar()


    Genesis Theme Customization and Help

    April 11, 2017 at 6:13 pm #204647
    Erika
    Participant

    Carasmo,

    Thank you so much! This worked perfectly!

    One last question: How do I filter out page titles?

    April 11, 2017 at 9:14 pm #204648
    carasmo
    Participant

    How do you skip specific page titles? I would make a helper like this using the page/post id:

    /** 
     *
     * Is Page Title Helper
     * @since  1.0.0
     *
     */
    function is_not_this_page() {
    	return ( (
    
    		is_page( array( 
    		'414', 
    		'530', 
    		'1107', 
    		'1589', 
    		'1638',
    		'1134',
    		'369' // last has no comma
    		) ) 
    			 
    	 ) ) ? true : false ;
    }

    Then apply it with the ! not conditional like this which says:

    is not admin and in the loop and is singular and not any of those pages in the array:

    function new_title( $title ) {
    
    	if( ! is_admin() && in_the_loop() && is_singular() && ! is_not_this_page()  ) {
    		$new_title = '<i class="ion-fork">x</i><br> ' . $title;
    		return $new_title;
    
    	}//end conditional
    	
    	return $title;
    }
    add_filter( 'the_title', 'new_title' );

    Genesis Theme Customization and Help

    April 11, 2017 at 9:19 pm #204649
    carasmo
    Participant

    Those are for pages, if this is a mixture of posts and pages use is_single instead in the is_not_this_page helper. Please read https://codex.wordpress.org/Conditional_Tags then you can see how to get what you want for your needs.


    Genesis Theme Customization and Help

    April 11, 2017 at 9:35 pm #204651
    carasmo
    Participant

    Oops, that is wrong. is_single is just posts and cpts but not pages.

    function is_not_this_page() {
    	
    	return ( (
    
    		//pages I don't want
    		is_page( array( 
    			'414', 
    			'530', 
    			'1107', 
    			'1134',
    			'369' // last has no comma
    		) ) 
    		
    		|| // or
    		
    		//posts and cpts I don't want
    		is_single( array( 
    			'123', 
    			'245', 
    			'789' // last has no comma
    		) ) 		
    			 
    	) ) ? true : false ;
    }

    Genesis Theme Customization and Help

    April 11, 2017 at 10:16 pm #204653
    Brad Dalton
    Participant

    Here's another method:

    add_action( 'wp_enqueue_scripts', 'bg_enqueue_ionicons' );
    function bg_enqueue_ionicons() {
    	wp_enqueue_style( 'ionicons', '//code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css', array(), CHILD_THEME_VERSION );
    }
    
    add_action( 'genesis_entry_header', 'icon_before_post_title', 5 );
    function icon_before_post_title() {
    if ( is_singular( 'post' ) ) {
    echo '<h1><i class="ion-fork entry-title"></i></h1>';
        }
    }
    

    Source


    2700 Genesis Tutorials

    April 12, 2017 at 2:22 pm #204696
    Erika
    Participant

    Thank you both! Both codes are effective.

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

© 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