skip to Main Content

First post here. I have a pretty simple problem that I can’t fix. I’m trying to add a hyperlink to some text my my footer. Can anyone give some tips on making the text a clickable link? Thanks!

Here is the code:

            <p class="mb-0"><?php printf( '&copy; %s %s', date( 'Y' ), esc_html__( 'Designed by Site. All rights reserved.', 'theme' ) ) ?></p>
            
        </div>

2

Answers


  1. Chosen as BEST ANSWER

    Thanks! This is what I ended up with:

    <?php echo "Designed by <a href='https://example.org>example.org</a> 2022. All Rights Reserved.<br/>"; ?>
    

  2. preg_replace has many important roles Here in this example, I have used this special PHP function to replace URL inside text block clickable.

    <?php
    
    $plaintext = "https://www.stackoverflow.com<br/>";
    
    echo url_to_clickable_link($plaintext);
    
    function url_to_clickable_link($plaintext) {
    
      return preg_replace(
      '%(https?|ftp)://([-A-Z0-9-./_*?&;=#]+)%i', 
      '<a target="blank" rel="nofollow" href="$0" target="_blank">$0</a>', $plaintext);
    
    }
    
    ?>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search