Prevent Admin Translation WPML
November 19, 2024 · AI Conversations
### 1. **Exclude Admin Pages or Sections**
WPML primarily translates front-end content. If WPML is affecting admin pages unnecessarily:
– Go to **WPML → Settings → Custom Fields Translation**.
– Review custom fields associated with admin pages and mark them as **Not translatable**.
### 2. **Disable Translation for Specific Text Domains**
If you want to exclude specific plugins or themes from being translatable:
– Navigate to **WPML → Theme and plugins localization**.
– Uncheck the plugins or themes that include admin-related text you don't want to translate.
### 3. **Prevent Translation of Specific Strings**
For specific admin strings:
– Go to **WPML → String Translation**.
– Locate the string you want to exclude.
– Unregister the string by clicking the **Trash** icon.
### 4. **Custom Code to Exclude Admin Areas**
Add a filter in your theme's `functions.php` file to prevent translation in admin areas:
add_filter('gettext', function ($translated_text, $text, $domain) {
// Check if in admin area and apply conditions
if (is_admin()) {
// Exclude specific text domains or strings
if ($domain === 'your-plugin-textdomain' || $text === 'Specific Admin String') {
return $text; // Return original text without translating
}
}
return $translated_text;
}, 10, 3);
### 5. **Turn Off WPML for Admin Sections**
If a plugin or functionality doesn't need WPML:
– In your plugin or theme code, wrap admin-related areas with `is_admin()` checks and avoid WPML API calls there.
### 6. **Disable WPML for Specific User Roles**
To restrict WPML translation features from affecting admin users:
– Add this snippet to `functions.php`:
add_action('init', function () {
if (current_user_can('administrator')) {
global $sitepress;
remove_action('wp_loaded', [$sitepress, 'some_wpml_function']);
}
});
### 7. **WPML Translation Management Settings**
Use **Translation Management** to assign translation permissions. Admin users can avoid translating unnecessary content by limiting string access.
Let me know if you need help implementing any of these solutions!
—
### **1. Disable WPML Admin Features for Admin Profile**
Add this code to your theme’s `functions.php` file or a custom plugin:
add_action('init', function () {
// Check if the current user is an administrator
if (current_user_can('administrator')) {
// Disable WPML actions for the admin profile
if (defined('ICL_SITEPRESS_VERSION')) {
global $sitepress;
remove_action('admin_bar_menu', [$sitepress, 'admin_language_switcher']);
remove_action('wp_footer', [$sitepress, 'footer_language_selector']);
remove_menu_page('wpml-menu'); // Hide WPML menu from admin
}
}
});
—
### **2. Hide WPML Dashboard Notifications for Admin**
WPML often displays dashboard notifications. To disable these for administrators, use the following code:
add_action('admin_head', function () {
if (current_user_can('administrator')) {
echo '<style>
#wpml-notices, #icl_dashboard_widget {
display: none !important;
}
</style>';
}
});
—
### **3. Disable WPML String Translation for Admin**
If WPML’s string translation is active in the admin for administrators, you can unregister specific strings:
add_filter('gettext', function ($translated_text, $text, $domain) {
if (is_admin() && current_user_can('administrator')) {
if ($domain === 'wpml' || $domain === 'sitepress') {
return $text; // Prevent translation
}
}
return $translated_text;
}, 10, 3);
—
### **4. Remove WPML Meta Boxes for Admin**
If WPML adds unnecessary meta boxes for administrators (e.g., language options), remove them:
add_action('do_meta_boxes', function () {
if (current_user_can('administrator')) {
remove_meta_box('icl_div_config', 'post', 'normal'); // Example: WPML meta box on posts
}
});
—
### **5. Prevent WPML Features for Admin Dashboard Pages**
You can fully disable WPML for admin dashboard pages accessed by administrators:
add_action('admin_init', function () {
if (current_user_can('administrator')) {
remove_action('wp_loaded', ['SitePress', 'maybe_redirect_to_wpml_home']); // Example WPML redirect
}
});
—
### **6. Modify WPML Settings for Admin Users**
You can configure WPML to not display features for admin users:
– Go to **WPML → Settings → User settings**.
– Limit WPML features for admin users, like language switchers, translation tools, or string translations.
—
This approach ensures WPML tools, translations, and features won't affect admin profiles while still being active for other user roles or on the front end. Let me know if you need further clarification!