Forums

How do I create a "speaking" block navigation menu? shortcode in the_title? (3 posts)

  1. automatyk
    Member
    Posted 1 year ago #

    Hello,

    I am trying to create a speaking block navigation as seen here: http://www.smashingmagazine.com/2008/02/26/navigation-menus-trends-and-examples/

    So for example: I can have a main title and some descriptive stuff right below but I would only want the main title to appear in page headlines without the descriptive text.

    I'm using the Thematic framework so my functions.php in my theme looks like:

    // shortcode [menusmall]navigation[/menusmall] to add span="menu_small" to navigation menu items
    
    	function menu_small_shortcode( $atts, $content = null ){
    	   		return '<span class="menu-small">' . $content . '</span><br/>';
    	}
    	add_shortcode('menusmall', 'menu_small_shortcode');
    	add_filter('the_title', 'do_shortcode');
    
    // strip the shortcode [menusmall] from the document title.
    	function strip_menusmall($content) {
    			$patterns = array();
    			$patterns[0] = '/\[menusmall\]/';
    			$patterns[1] = '/\[\/menusmall\]/';
    			$replacements = array();
    			$replacements[0] = '';
    			$replacements[1] = '';
    			$content = preg_replace($patterns, $replacements, $content);
    			return $content;
    	}
    
    	add_filter('thematic_doctitle', 'strip_menusmall');
    	add_filter('thematic_doctitle', 'do_shortcode');

    However, this method presents a problem whenever the_title is referenced so I'm stripping out the shortcode but there's got to be a better way.

    Can someone point me in the right direction? Thanks.

  2. automatyk
    Member
    Posted 1 year ago #

    I guess the question here boils down to... is there a way to change the behavior of a shortcode based on the hook that uses it.

  3. automatyk
    Member
    Posted 1 year ago #

    D'oh! Sometimes it pays to read the manual: http://themeshaper.com/wordpress-menu-tricks/

Topic Closed

This topic has been closed to new replies.

About this Topic