Support Log in

23. Content Filters

Developer Guide
Prefer video? Watch the Lang Forge tutorials 9 short guides covering every feature Watch

Filters that modify content output based on language context.

post_link / page_link / post_type_link — Permalink Filtering

Permalinks are filtered to include the language prefix or parameter based on the post’s _lf_language meta. This applies to all get_permalink() calls.

Example: Add custom query args to translated permalinks
php
add_filter('post_link', function ($url, $post) {
    $lang = lf_get_post_language($post->ID);
    $default = lf_get_default_language();

    // Add a tracking parameter for non-default languages
    if ($lang !== $default) {
        $url = add_query_arg('ref', 'translation', $url);
    }
    return $url;
}, 20, 2);

lf_translatable_post_types — Control Which Post Types Are Translatable

php
/**
 * Filter the list of translatable post types.
 *
 * @param array $post_types Array of post type slugs
 * @return array Modified array
 */
add_filter('lf_translatable_post_types', function ($post_types) {
    // Add your custom post types
    $post_types[] = 'portfolio';
    $post_types[] = 'testimonial';

    // Remove a default type if needed
    $post_types = array_diff($post_types, ['attachment']);

    return $post_types;
});

lf_woo_sync_meta_keys — Control WooCommerce Field Sync

php
/**
 * Filter which WooCommerce meta keys are synced across translations.
 *
 * @param array $keys Array of meta key strings
 * @return array Modified array
 */
add_filter('lf_woo_sync_meta_keys', function ($keys) {
    // Remove price from sync (for region-specific pricing)
    return array_diff($keys, ['_regular_price', '_sale_price', '_price']);
});
Example: Filtering the gettext output for a specific language
php
// Override WooCommerce button text for Russian
add_filter('gettext', function ($translation, $text, $domain) {
    if (lf_get_current_language() !== 'ru') return $translation;

    if ($domain === 'woocommerce' && $text === 'Add to cart') {
        return 'В корзину';
    }
    return $translation;
}, 20, 3);

Forge AI Assistant Online

Hi! I'm the Lang Forge AI assistant. Ask me anything about the plugin — setup, features, troubleshooting, or development.

Just now
Powered by Forge AI · Browse docs