If you have static text with dynamic content then you can use.
printf( esc_attr___('static text goes here with %s', 'text-domain' ), $title );
If you have only $title then no need to translate it.
Just escape it.
echo esc_attr( $title );
Note esc_attr
, esc_attr__
and esc_attr_e
used for escaping dynamic values from HTML element attributes.
E.g.
`<div class="<?php echo esc_attr( $class ); ?>">`
And esc_html
, esc_html__
and esc_html_e
used for escaping dynamic values from HTML content.
E.g.
<div> <?php echo esc_html( $title ); ?> </div>
Related Posts:
- Data Validation & Sanitization for Big HTML Blocks
- How to create .pot files with POedit?
- Enqueue Stylesheets After Theme’s “rtl.css”
- Caching and Versioning for rtl.css
- Use __($str) and _e($str) to translate strings with HTML
- Can I create customizer setting that can handle plugin shortcode?
- How to sanitize select box values in post meta?
- What is the purpose of an extra file for translation?
- Translated strings not appearing – what am I missing?
- Remove frameborder attribute from iframes
- How to change i18n/l10n of #reply-title? (Old title: Comment reply link not working)
- Internationalization and functions that use it
- Theme translation not applying
- 2 localizations inside a WordPress theme
- Should I change text-domain of TGM library inside theme?
- Change locale by detecting viewer’s browser language setting and let them choose prefered language after
- Single translation for many locales
- What is the safe way to print tracking code / pixel code before tag or tag
- correct tags for validating input types
- Does the textdomain have to be the theme’s name?
- How to escape html generate by a loop
- How to escape multiple attribute at once in WordPress?
- Do I need to include a textdomain if my theme doesn’t support translation?
- Contact Form Security
- How to allow certain PHP functions when using sanitize_callback in the word press customizer
- Data Validation in wordpress
- using Options Framework – can “theme-textdomain” domain be changed?
- Translate a theme with a PO file
- how to unlocalize theme/plugin?
- How to set different localization file for different users?
- Menu names not getting translated
- How to generate a rtl.css file for themes?
- Trouble creating custom sanitization function when uploading video files
- Enqueue Stylesheets After Theme’s “rtl.css”
- Display Today’s date outside the loop?
- What are these variables and where are they documented?
- Is there a way to prevent wp_head from outputting self-closing tags?
- Javascript localization doesn’t load. How to Internationalize javascript without plugin?
- Menu items description? Custom Walker for wp_nav_menu()
- How to define and link full path to css located at a random folder on header.php
- Sizing screenshot.png without losing aspect ratio
- Software for WordPress Theme and Plugin Development? [closed]
- When to use is_home() vs is_front_page()?
- What is the preferred way to add custom javascript files to the site?
- Get the blog page URL set in Options
- How do I get the theme URL in PHP?
- Why when I submit a form in wordpress it loads a 404 page though URL is correct
- What is the constant WP_USE_THEMES for?
- Worthwhile to restrict direct access of theme files?
- How Do I Protect My Premium WordPress App Theme from Copying?
- How to detect mobile devices and present them a specific theme?
- Using wp_add_inline_style without a stylesheet
- How to add posts to custom menus?
- WordPress Theme Preview Image
- How To extend WP_Customize_Control
- What is the difference between front-page.php and home.php? [duplicate]
- How can I get page slug
- Does the functions.php file ever get called during an AJAX call? Debug AJAX
- When to use _e and __ for the translation?
- What is a Theme textdomain?
- How to show a custom meta box on the “Quick Edit” screen?
- How to add CSS class to custom logo?
- How to add custom css file in theme?
- How important is it to enqueue a theme’s stylesheet?
- CSS not updating in browser when I change it
- Display Search Result Count
- wp_nav_menu(), how to change class?
- In Which Contexts are Plugins Responsible for Data Validation/Sanitization?
- theme path in javascript file
- Is wp_is_mobile() effective?
- Display Menu Name using wp_nav_menu
- Making update notification functionality for my themes
- What questions do you ask when asked to give an estimate on theme development?
- How to remove dashicons.min.css from frontend?
- How do I remove a pre-existing customizer setting?
- Minimum Template Files for Theme Development
- What’s the difference between home.php and index.php?
- pass object/JSON to wp_localize_script
- get_template_part vs action hooks in themes
- Theme Activate Hook
- Solutions for generating dynamic javascript / CSS
- wp_redirect() – headers already sent
- Can I create my own “Recent Posts” widget or customize the existing one?
- Custom single template for a specific category
- how can I add an icon/image for a child theme?
- How can I add a URL field to the attachments window?
- The the_post_thumbnail without srcset?
- The proper way to include/require PHP files in WordPress
- Get the first image from post content (eg.: hotlinked images)
- after_setup_theme always runs
- When to use add_action(‘init’) vs add_action(‘wp_enqueue_scripts’)
- Getting failure when using filemtime() with wp_enqueue_style
- Do I actually need to link my theme’s style.css in the theme files
- Why is wp_head() creating a top margin at the top of my theme header?
- How to store widget fields data as an array?
- How do I add version control to my workflow?
- Using classes instead of global functions in functions.php
- WordPress API Menu/Submenu Order
- How can I display a menu on certain pages only?
- Enqueue a stylesheet for login page and make it appear in head element