Skip to navigation
Filters and hooks what are involved in wordpress translate page
22.10.25
Below is a comprehensive, practical list of WordPress filters/actions you will likely need to hook in order to translate a site “completely.” I group them by concern and include a short note on what each hook covers and why you might need it. Use gettext-based filters for most UI strings, content filters for post/page HTML, URL/asset filters for links and images, REST/block filters for headless or block-rendered content, and plugin-specific hooks (WooCommerce, etc.) where needed. Quick recommended approach Strings (themes/plugins/core UI): gettext / gettext_with_context / ngettext / ngettext_with_context. Post/page content and block HTML: render_block and the_content. Titles/excerpts/menus/widgets/shortcodes/comments: the_title / the_excerpt / wp_setup_nav_menu_item / widget filters / do_shortcode_tag. URLs, assets and attachments: home_url / site_url / option_siteurl / template_directory_uri / plugins_url / script_loader_src / style_loader_src / wp_get_attachment_* filters. REST API / AJAX / feeds: rest_prepare_, rest_post_dispatch, wp_ajax_, feed/content feed filters. Plugin/theme-specific hooks: scan for plugin filters (WooCommerce has many). Core i18n (translate strings provided by themes/plugins/core) gettext — central filter for translated strings (translated text, original text, domain). gettext_with_context — same but with context. ngettext — plural forms (translated text for pluralization). ngettext_with_context — plural with context. locale — change/override current locale (use with care). load_textdomain_mofile — inspect/override loaded translation file (rare). Post / page / block content the_content — post content (classic filter for frontend HTML). the_excerpt — excerpt output. get_the_excerpt — retrieving excerpt. render_block — filter rendered block HTML (useful to translate block output text while preserving markup). do_shortcode_tag — filter shortcode output (translate the output of shortcodes). the_title — post/page title output. single_post_title — used in some themes. the_title_attribute — title attributes (used in tags/links). Titles, menus & navigation wp_setup_nav_menu_item — modify nav menu item object (URLs/titles). wp_nav_menu_items — alter entire menu HTML. nav_menu_item_args — nav menu args. nav_menu_link_attributes — attributes for menu anchor tags. nav_menu_item_title — menu item titles. Widgets & sidebars widget_display_callback — alter widget instance just before rendering. dynamic_sidebar_params — sidebar/widget parameters. widget_title — widget title output. widget_text — legacy text widget (or widget_text_content depending on WP version). widget_text_content — filter for text widget content (for newer WP). Shortcodes & filters do_shortcode_tag — as above (shortcode output). pre_do_shortcode_tag (if present in WP version) — hook before shortcode processed. Comments, authors & metadata comment_text — comment content. get_comment_text — retrieving comment content. get_comment_author — comment author name. get_comment_author_url — author URL. Media, images & attachments wp_get_attachment_image_attributes — image tag attributes (src, srcset, alt). wp_get_attachment_url — attachment URL. wp_get_attachment_metadata — metadata (sizes, file paths). wp_get_attachment_image_src — returns image src array (filterable). wp_calculate_image_srcset — srcset calculation (filter inputs). wp_prepare_attachment_for_js — used by media library/REST responses. URLs, site and asset sources option_siteurl — used to override the siteurl option (common for domain swapping). site_url — filter when building site URLs. home_url — filter for home URL. template_directory_uri — theme template directory URL. stylesheet_directory_uri — child/stylesheet dir URL. plugins_url — plugin URL for enqueued assets. content_url — wp-content URL. upload_dir — filter for uploads dir array (paths/URLs). pre_get_shortlink — shortlink generation. get_canonical_url — canonical URL filter. Enqueued scripts/styles and tags script_loader_src — URL for enqueued scripts. style_loader_src — URL for enqueued styles. script_loader_tag — filter the script tag (attributes) or to inject locale-specific data. style_loader_tag — filter the link tag for styles. wp_script_attributes — attributes added to script tag. wp_style_add_data — occasionally used for style data. wp_resource_hints — preconnect/prefetch/prerender resource hints. Template/HTTP output buffering template_redirect (use ob_start to filter full HTML output) — useful to replace site URLs across rendered HTML (but risky for performance/edge cases). REST API / AJAX / headless endpoints rest_prepare_post (and rest_prepare_{post_type}) — modify REST response for posts and custom post types. rest_prepare_comment, rest_prepare_user, rest_prepare_attachment — modify other REST responses. rest_post_dispatch — last chance to modify REST response body. rest_pre_echo_response — alter raw response being echoed. wp_ajax_* and wp_ajax_nopriv_* — AJAX endpoints (if you need to translate responses from custom AJAX handlers). rest_pre_insert_* / rest_pre_update_* — alter content before DB insert via REST. Feeds and external outputs the_content_feed — content for feeds. the_excerpt_rss — excerpt used in RSS. atom_entry — feed entry hooks (less commonly used). Emails & notifications wp_mail — filter outgoing mail args (subject/body/headers). wp_mail_from / wp_mail_from_name — sender fields. woocommerce_email_subject_* / woocommerce_email_headers / woocommerce_email_body_* — plugin-specific (WooCommerce). Database/save time (translate before saving or to keep translations stored) content_save_pre — filter content before saving to DB (if you want to store translated versions on save). wp_insert_post_data — alter sanitized post data before insert/update. add_post_meta / update_post_meta filters don't exist directly, but use sanitize_post_meta or filter the meta outputs (get_post_metadata via filter 'get_post_metadata'). Gutenberg / editor and block-specific render_block — (mentioned) filter rendered block HTML. register_block_type_args — intercept block registration args including render_callback. block_type_metadata — used when registering. gutenberg_get_block_editor_settings (older) / block_editor_settings_all — editor settings (if translating editor UI strings). Search, forms and queries get_search_form — filter the HTML for search form. get_search_query — search query string. posts_results / the_posts — modify posts list output (rare). Admin & backend (if translating admin UI or saving translated strings) admin_enqueue_scripts — if translating admin strings in enqueued scripts. admin_notices — for localized notices. admin_footer_text — filter admin footer. user_profile_update_errors — validate/alter user profile fields; not standard for translation but sometimes needed. Short-lived / performance object caching/transients: set_transient/get_transient — use to cache translations (e.g., external API results). wp_cache_add/wp_cache_get — low-level cache if needed. Plugin & third-party specific hooks (examples) WooCommerce: product strings, cart API, endpoints: e.g., woocommerce_get_product_thumbnail, woocommerce_gallery_image_html_attachment_image_params, woocommerce_store_api_cart_item_images, woocommerce_email_subject_{id}, many more. Search plugin docs for rest hooks. Yoast / SEO plugins: filters for meta title/description, canonical URL filters. Advanced Custom Fields (ACF): acf/format_value filters to translate field values, acf/load_value, acf/update_value. WPML/Polylang/TranslatePress: these provide their own filters/APIs; integrate rather than reimplement. Practical checklist (what to hook for “complete” coverage) gettext / gettext_with_context / ngettext / ngettext_with_context — translate UI strings from plugins/themes. the_content / render_block — translate post content and blocks (render_block is essential with Gutenberg). the_title / the_excerpt / get_the_excerpt — titles and excerpts. do_shortcode_tag — shortcode outputs. wp_setup_nav_menu_item + nav_menu_item_title + nav_menu_link_attributes — menus. widget_display_callback + widget_title + widget_text_content — widgets. wp_get_attachment_image_attributes + wp_get_attachment_url + wp_get_attachment_metadata — media and image URLs. script_loader_src + style_loader_src + script_loader_tag + style_loader_tag — enqueued asset URLs & tags. home_url + site_url + option_siteurl + template_directory_uri + plugins_url — base URLs and template/plugin URLs. rest_prepare_* + rest_post_dispatch — REST API responses. the_content_feed / the_excerpt_rss — feed content. wp_mail / wp_mail_from / wp_mail_from_name — outgoing email subjects/bodies. template_redirect output buffering as a last-resort to replace remaining hard-coded occurrences in final HTML. Plugin-specific filters (WooCommerce, ACF, Yoast, etc.) — scan and add per-plugin. Notes, caveats and best practices gettext (and plural/context variants) is the best place to target UI strings produced by properly internationalized code (i18n). If a theme/plugin uses __(), _e(), _n() etc., gettext filters are ideal. For HTML content (posts), translate only text nodes if possible. Replacing across whole HTML with str_replace is easier but risks breaking attributes, JSON inside scripts, serialized data, or markup. Consider parsing DOM and translating text nodes only. render_block is required for blocks: Gutenberg renders blocks server-side via render_block, so hooking there avoids breaking block markup. For URLs and assets, use the source filters (script_loader_src / style_loader_src / plugins_url / upload_dir) rather than post-render string replacement — safer and more efficient. REST API: if site is used headlessly or consumed programmatically, translate REST responses using rest_prepare_* to avoid corrupting JSON. Performance: external translation APIs must be cached (transients) and rate-limited. Translating every string on the fly will be slow. Ordering matters: apply gettext early if you want translated strings to be used by other filters. Be cautious modifying output twice. Test with multilingual plugins (WPML, Polylang, TranslatePress) — they may already do much of this; integrating is usually better than duplicating behavior. Scan plugin/theme code for custom filters and hook points — no single list covers every plugin’s custom hooks. If you want, I can: produce a starter ClassTranslator (dictionary + HTML-aware) that hooks the most important filters above and shows how to translate text nodes only, or generate a checklist file you can drop into your plugin that registers no-op hooks for all the filters above so you can iterate and add translations where needed, or scan your repo for existing usage of these hooks and point to places to attach translations (I can run a code search against the repo if you want).
https://developer.wordpress.org/reference/hooks/gettext/
Reply
Anonymous
Information Epoch 1772315346
Think parallel.
Home
Notebook
Contact us