admin管理员组文章数量:1124403
I've been trying to figure this out for a while and I can't seem to figure it out using <br>
or \n
but not sure where to place it. I've got this php line for email results and I want to place a line break in between the sentences. No matter what I try it crashes the site.
Here is the line:
'post_alert_user' => esc_html__('Thank you for your submission at ', 'usp-pro') .$user['admin_name'] . esc_html__('! If submissions require approval, you'll receive an email once it's approved.', 'usp-pro'),
So basically, I want the email results to look like this instead of running all in one line:
Thank you for your submission at HIV Heros!
If submissions require approval, you'll receive an email once it's approved.
I've been trying to figure this out for a while and I can't seem to figure it out using <br>
or \n
but not sure where to place it. I've got this php line for email results and I want to place a line break in between the sentences. No matter what I try it crashes the site.
Here is the line:
'post_alert_user' => esc_html__('Thank you for your submission at ', 'usp-pro') .$user['admin_name'] . esc_html__('! If submissions require approval, you'll receive an email once it's approved.', 'usp-pro'),
So basically, I want the email results to look like this instead of running all in one line:
Share Improve this question edited Feb 28, 2024 at 19:09 Pat J 12.3k2 gold badges28 silver badges36 bronze badges asked Feb 28, 2024 at 18:15 diegoindigodiegoindigo 112 bronze badges 3 |Thank you for your submission at HIV Heros!
If submissions require approval, you'll receive an email once it's approved.
2 Answers
Reset to default 0You are using single quotation in single quotation which is not possible, use one of the below approch,
Approch 1 (' \' ')
:
'post_alert_user' => esc_html__('Thank you for your submission at ', 'usp-pro') .$user['admin_name'] . esc_html__('! If submissions require approval, you\'ll receive an email once it\'s approved.', 'usp-pro'),
Approch 2 (" ' ")
:
'post_alert_user' => esc_html__('Thank you for your submission at ', 'usp-pro') .$user['admin_name'] . esc_html__("! If submissions require approval, you'll receive an email once it's approved.", 'usp-pro'),
You have few issues with your string trnalation.
- Any of
esc_html*
function will escape html tabs, so you can't directly use line brake<br>
and\n
will be ignored too if it's a html email. - Concatenate string will brake translation (E.G. to RTL) in different language.
- And an unescaped single quote (
'
) symbol. You can wrap your string with double quote ("
) or use escape character (E.G.'you\'ll receive'
).
To fix everything it's recommended to use printf()
or sprintf()
function with appropriate placeholders and translators comment.
You can also use wp_kses()
or wp_kses_post()
to output strings with html tags. Keep in mind kses functions are slow.
Examples:
$data = [
// ...
'post_alert_user' => sprintf(
/* translators: 1. Admin Name, 2. Line brake (br tag) */
esc_html__('Thank you for your submission at %1$s!%2$sIf submissions require approval, you\'ll receive an email once it\'s approved.', 'usp-pro'),
esc_html( $user['admin_name'] ),
'<br>'
),
// ...
];
本文标签: eschtml Line break
版权声明:本文标题:esc_html Line break 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736629282a1945742.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
'
s (single quotes) in a string wrapped in'
(single quotes); either change the inner'
s to\'
or else wrap the string in"
(double quotes). – Pat J Commented Feb 28, 2024 at 19:10