Home > Enterprise >  Adding Link To Footer PHP Copywriting Text
Adding Link To Footer PHP Copywriting Text

Time:07-08

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 ><?php printf( '&copy; %s %s', date( 'Y' ), esc_html__( 'Designed by Site. All rights reserved.', 'theme' ) ) ?></p>
            
        </div>

CodePudding user response:

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);

}

?>

CodePudding user response:

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/>"; ?>
  • Related