2

How do I put the homepage link ? Right now it's not correct.

     <p><?php _e( 'The page you are looking for is not here. Why don’t you try the <a href="<?php echo esc_url( home_url( '/' ) ); ?>">homepage</a>?', 'braveandco' ); ?></p>

2 Answers 2

5

You are using PHP inside a single quote and a malformed one at that. That won't work. Step one is to get that string right:

_e( 'The page you are looking for is not here. Why don’t you try the <a href="'.esc_url( home_url( '/' ) ).'">homepage</a>?', 'braveandco' );

That is pure PHP. Check PHP's manual for proper string construction and for the concatenation operators.

Now, the _e() function is a language translation string. That means it is supposed to be replaceable by translations into other languages. Since you have a dynamic component, that translation could be tricky. In fact, what you are doing now is exactly what the Codex instructs you not to do. What you want to do instead is provide a stable string for translation then switch in whatever dynamic components you need.

printf(
  __( 
    'The page you are looking for is not here. Why don’t you try the <a href="%s">homepage</a>?', 
    'braveandco' 
  ),
  esc_url( home_url( '/' ) )
);
1

Looks like bad syntax - try:

 <p><?php _e( 'The page you are looking for is not here. Why don’t you try the <a href="' . esc_url( home_url( '/' ) ) . '">homepage</a>?', 'braveandco' ); ?></p>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.