• The original /inc/template-tags.php file has following function:

    function twentytwenty_site_description( $display = true ) {
    	$description = get_bloginfo( 'description' );
    	if ( ! $description ) {
    		return;
    	}
    	$wrapper = '<div class="site-description">%s</div><!-- .site-description -->';
    	$html = sprintf( $wrapper, esc_html( $description ) );
    	$html = apply_filters( 'twentytwenty_site_description', $html, $description, $wrapper );
    	if ( ! $display ) {
    		return $html;
    	}
    	echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
    }

    To link tagline (site-description) to home url, I changed the 6th line to:
    $wrapper = '<a class="site-description" href="/">%s</a><!-- .site-description -->';

    Of course it’s not the correct way. Can someone please publish the code that need to be put in Child Theme function.php file?
    Thank you.

    • This topic was modified 1 year, 11 months ago by scott_ease.
    • This topic was modified 1 year, 11 months ago by scott_ease.
Viewing 6 replies - 1 through 6 (of 6 total)
  • I have done a quick test to add the following code and it does seem to work:

    $wrapper = '<div class="site-description"><a href="https://yourfullsiteurl.com/">%s</a></div><!-- .site-description -->';

    That being said, if you edit the theme files, the changes will be overwritten and lost when your theme updates.

    Instead, you can add this php code snippet:

    add_filter('option_blogdescription', 'replace_blogdescription');
    
    function replace_blogdescription($description) {
    
    echo '<div class="site-description"><a href="https://yourfullsiteurl.com/">YOUR SITE DESCRIPTION</a></div><!-- .site-description -->';
    
    }

    Make sure you replace “YOUR SITE DESCRIPTION” with the tagline you want to use and the sample link “https://yourfullsiteurl.com/&#8221; with your site’s actual website.

    If you are not sure how to add php code, there are a couple of paths:

    1. Use a plugin such as Code Snippets (I would recommend this if you are new)
    2. Create a child theme
    3. Create your own plugin

    I hope that helps!

    • This reply was modified 1 year, 11 months ago by Alvaro Gómez.
    Thread Starter scott_ease

    (@scott_ease)

    In this case, the description can no longer be edited from admin panel. Is it possible to just overwrite $wrapper using php code snippet in Child Theme function.php file? Thank you.

    • This reply was modified 1 year, 11 months ago by scott_ease.

    That’s right. The code I shared “hard codes” the URL and the tagline. You can add this code and it will output the current Tagline and Site URL automatically:

    
    function filter_bloginfo( ) {
    	$url = site_url();
    	$description = get_bloginfo( 'description' );
    
    	$description = '<div class="site-description"><a href="' . $url . '">' . $description . '</a></div><!-- .site-description -->';
    	return $description;
    }
    add_filter( 'twentytwenty_site_description', 'filter_bloginfo');
    

    Let me know if that helps!

    • This reply was modified 1 year, 11 months ago by Alvaro Gómez.
    Thread Starter scott_ease

    (@scott_ease)

    It works. I appreciate!

    If I’d like to use “My <*strong*>Impressive<*/strong*> Description” as tagline, how to make the program recognize html code?

    With some other old themes, I can just change header.php file in Child Theme, replacing <?php bloginfo( ‘description’ ); ?> with <?php echo html_entity_decode(get_bloginfo(‘description’)); ?>.

    But TwentyTwenty is coded different from previous themes. Is there a piece of php code snippet to make that happen?
    Thank you.

    • This reply was modified 1 year, 11 months ago by scott_ease.
    • This reply was modified 1 year, 11 months ago by scott_ease.

    Hi @scott_ease.

    Are you using the strong tag as an example or do you have in mind to use some other type of more complex markup at some point?

    I am asking because it would be orders of magnitude easier to simply style that link, right?

    .site-description a {font-weight:700} …or something to that effect.

    This might be terribly obvious but I thought I should ask first ??

    • This reply was modified 1 year, 11 months ago by Alvaro Gómez.
    Thread Starter scott_ease

    (@scott_ease)

    Only style part (not entire) of the description with color, margin, font weight or size. That’s why I need the tagline to recognize html code. Thank you.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Link site-description to url’ is closed to new replies.