• While a click on the title links to the homepage I want to make the subtitle clickable as well.

    Is there a way to add one or more hyperlinks to the subtitle?

    The use case is that the subtitle tells something of my permanent service offerings and should be reachable with one click.

    Referring Website: https://cloudero.de

Viewing 1 replies (of 1 total)
  • Hi @flashlight1405!

    For a single link, you could create a child theme and make a copy of the parent theme’s header.php file in your child theme folder.

    Then locate this line:

    <h2 class="site-description"><?php bloginfo( 'description' ); ?></h2>

    and turn it into a link, like this:

    <h2 class="site-description"><a href="https://www.ads-software.com"><?php bloginfo( 'description' ); ?></a></h2>

    Obviously, you’d want to put your own URL in there instead of www.ads-software.com ??

    For multiple links, it gets a little more involved. It looks like you’re separating the different parts of your tagline with periods:
    Digitalisierung. Interimsmanagement. IT.
    If you want each of those to be it’s own link, we can use those periods in a filter to split the tagline up into separate pieces.

    function tagline_links( $text, $show ) {
    	if ( 'description' == $show ) {
    		// Start by defining our links
    		$urls = array(
    			'https://wordpress.com',
    			'https://www.ads-software.com',
    			'https://www.ads-software.com/support/topic/add-a-link-to-the-subtitle/',
    		);
    
    		// Separate our tagline into blocks, using periods (.) as markers
    		$parts = explode( '. ', $text );
    		// Combine those into a single array
    		$link_pairs = array_combine( $urls, $parts );
    		// Loop through our new array and use it to build the links
    		foreach ( $link_pairs as $k => $v ) {
    			$link    = ' <a href="' . $k . '">' . $v . '</a>';
    			$links[] = $link;
    		}
    		// Combine the links into our new tagline, separated by a period and a space
    		$text = implode( '. ', $links );
    
    	}
    
    	return $text;
    }
    
    add_filter( 'bloginfo', 'tagline_links', 10, 2 );

    If you drop that into the functions.php file of your child theme, you can replace the three URLs at the beginning of the code with the addresses you want to send people to (in the same order they appear in your tagline).

    Then the function takes your tagline and breaks it up at the periods, making a second list.

    Then it combines those lists, matching the first chunk of the tagline with the first URL, the second chunk with the second URL and so on.

    Now that it has those items paired up, it makes one last list, this time of HTML links with your URLs and text bits.

    Finally, it combines the different parts of that list into a new tagline and prints it out.

    The last part will be some CSS to style them. When you first turn them into links they’ll take on some different CSS effects. This will reset that:

    .site-description a,
    .site-description a:visited {
        font-weight: 300;
        text-align: center;
        text-transform: none;
        color: #767676;
    }

    That should do the trick – let me know how it goes! ??

Viewing 1 replies (of 1 total)
  • The topic ‘Add a link to the subtitle’ is closed to new replies.