Reputation: 35
I want to put a clickable text inside a PHP text, how to do that?
this is my code, the link should be in (click here)
<p><?php _e("some text click here some text", 'var');?></p>
Upvotes: 0
Views: 10986
Reputation: 124
You use seemingly Wordpress so this is not a php function but a Wordpress function _e ();
Here is a link and you can see how to do it with Wordpress:
https://wordpress.stackexchange.com/questions/114201/html-inside-or-e-language-translation-string
But if you want to do that only with php, then an echo with your link in the text as well as in HTML will suffice:
<?php echo 'This is a link <a href="https://developer.wordpress.org/reference/functions/_e/">click here</a> for more.';
But you can also write a function yourself that works like Wordpress:
https://developer.wordpress.org/reference/functions/_e/
Use the simple form or break out the markup
<?php echo __( 'Please read <a href="https://goo.gl">this</a>', 'example-domain' );
or, but all not good by translation
<?php _e( 'This is a link <a href="https://wordpress.stackexchange.com/questions/165357/how-to-make-a-text-with-hyperlink-translatable-in-wordpress">click here</a> for more', 'example-domain' );
break out the html, try this one and you can more shorten this but for understand
$anchor = esc_html_x( 'Google', 'link text for google.com', 'txt-domain' );
$domain = esc_url( __( 'google.com', 'txt-domain' ) );
$link = sprintf( '<a href="https://%s">%s</a>', $domain, $anchor );
/* translators: 1 is a link with text "Google" and URL google.com */
echo sprintf( esc_html__( 'Use %1$s to search.', 'example-domain' ), $link );
The web is full of stuff:
Upvotes: 1