Community Forums › Forums › Archived Forums › Design Tips and Tricks › Force a line break in site title
Tagged: line break, php, site title
- This topic has 3 replies, 2 voices, and was last updated 10 years, 9 months ago by
SMMP.
-
AuthorPosts
-
July 16, 2014 at 5:54 am #114502
SMMP
MemberI'm administering some 30 websites with awfully long site titles. Many of them should display in two lines.
http://static2.smmp.de
Setting the max-width of site-title for each site and each display size is somewhat cumbersome.
Does anybody know another way of entering a line break into the site title?July 16, 2014 at 5:55 am #114504Brad Dalton
ParticipantReduce the title area in the CSS or filter the title and add the <br>
July 16, 2014 at 7:45 am #114518SMMP
MemberFiltering the title is what I had in mind, Brad. Unfortunately, I haven't the faintest clue how to do that.
July 19, 2014 at 6:53 am #114907SMMP
MemberI got it done by a very capable company in India.
Now I can make a line break by entering a simple asterisk (*) in title and description.
Here's the code for functions.php for everybody to enjoy://// ********************************************************* ////// //// CUSTOM CODE USED TO GENERATE CUSTOM TITLE AND DESCRIPTION ////// //// ********************************************************* ////// $new_general_setting = new new_general_setting(); class new_general_setting { function new_general_setting( ) { add_filter( 'admin_init' , array( &$this , 'register_fields' ) ); } function register_fields() { register_setting( 'general', 'custom_blog_info_title', 'esc_attr' ); register_setting( 'general', 'custom_blog_info_description', 'esc_attr' ); add_settings_field('custom_site_title', '<label for="custom_blog_info_title">'.__('Custom Site Title' , 'custom_blog_info_title' ).'</label>' , array(&$this, 'fields_html_title') , 'general' ); add_settings_field('custom_site_descripition', '<label for="custom_blog_info_description">'.__('Custom Site Description' , 'custom_blog_info_description' ).'</label>' , array(&$this, 'fields_html_desc') , 'general' ); } function fields_html_title() { // Custom Site Title $title_value = get_option( 'custom_blog_info_title', '' ); echo '<input type="text" id="custom_blog_info_title" name="custom_blog_info_title" value="' . $title_value . '" />'; } function fields_html_desc() { // Custom Site Description $desc_value = get_option( 'custom_blog_info_description', '' ); echo '<input type="text" id="custom_blog_info_description" name="custom_blog_info_description" value="' . $desc_value . '" />'; } } remove_action( 'genesis_site_title', 'genesis_seo_site_title' ); add_action( 'genesis_site_title', 'custom_genesis_seo_site_title' ); function custom_genesis_seo_site_title() { $new_title = get_option( 'custom_blog_info_title' ); $new_title = str_replace('*', '<br />', $new_title); //* Set what goes inside the wrapping tags $inside = sprintf( '<a href="%s">%s</a>', trailingslashit( home_url() ), $new_title ); //* Determine which wrapping tags to use $wrap = is_home() && 'title' === genesis_get_seo_option( 'home_h1_on' ) ? 'h1' : 'p'; //* A little fallback, in case an SEO plugin is active $wrap = is_home() && ! genesis_get_seo_option( 'home_h1_on' ) ? 'h1' : $wrap; //* And finally, $wrap in h1 if HTML5 & semantic headings enabled $wrap = genesis_html5() && genesis_get_seo_option( 'semantic_headings' ) ? 'h1' : $wrap; //* Build the title $title = genesis_html5() ? sprintf( "<{$wrap} %s>", genesis_attr( 'site-title' ) ) : sprintf( '<%s id="title">%s</%s>', $wrap, $inside, $wrap ); $title .= genesis_html5() ? "{$inside}</{$wrap}>" : ''; //* Echo (filtered) echo apply_filters( 'genesis_seo_title', $title, $inside, $wrap ); } remove_action( 'genesis_site_description', 'genesis_seo_site_description' ); add_action( 'genesis_site_description', 'custom_genesis_seo_site_description' ); function custom_genesis_seo_site_description() { //* Set what goes inside the wrapping tags $inside = esc_html( get_option( 'custom_blog_info_description' ) ); $inside = str_replace('*', '<br />', $inside); //* Determine which wrapping tags to use $wrap = is_home() && 'description' === genesis_get_seo_option( 'home_h1_on' ) ? 'h1' : 'p'; //* And finally, $wrap in h2 if HTML5 & semantic headings enabled $wrap = genesis_html5() && genesis_get_seo_option( 'semantic_headings' ) ? 'h2' : $wrap; //* Build the description $description = genesis_html5() ? sprintf( "<{$wrap} %s>", genesis_attr( 'site-description' ) ) : sprintf( '<%s id="description">%s</%s>', $wrap, $inside, $wrap ); $description .= genesis_html5() ? "{$inside}</{$wrap}>" : ''; //* Output (filtered) $output = $inside ? apply_filters( 'genesis_seo_description', $description, $inside, $wrap ) : ''; echo $output; } //// ********************************************************* ////// //// CUSTOM CODE USED TO GENERATE CUSTOM TITLE AND DESCRIPTION ////// //// ********************************************************* //////
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.