• wyclef

    (@wyclef)


    Hi, is there a way to add line breaks to one text field with esc_html__ included in the echo? Working with a theme that has the following line and have a need for 2-3 lines and would prefer to just be able to add some line breaks since this is an isolated instance that would only be used once rather than try to register new text fields.

    <span><?php echo esc_html__('Title: ', 'theme-core').esc_html($title); ?></span>

Viewing 4 replies - 1 through 4 (of 4 total)
  • Vijay Hardaha

    (@vijayhardaha)

    You can’t add html in esc_html functions but you can do something like This
    <span><?php printf( '<span>%s<br/>%s</span>', esc_html__( 'Title:', 'theme-core' ), esc_html( $title ) ); ?></span>

    Adjust your linebreaks as per your need <span>%s<br/>%s</span> it’s just an example to use HTML

    Thread Starter wyclef

    (@wyclef)

    I see. How would you go about modifying that $title to allow for line breaks, or a p tag or something.

    Vijay Hardaha

    (@vijayhardaha)

    You can’t do that while saving title in the database, but when it’s fetched as plain text then you can modify it as you want.

    Since esc_html__ ultimately uses htmlspecialchars, you could maybe use this solution from php.net (https://www.php.net/manual/en/function.htmlspecialchars.php#101592)

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘?add line breaks to esc_html__?’ is closed to new replies.