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 _langforge_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 = langforge_get_post_language($post->ID);
    $default = langforge_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);

langforge_translatable_post_types — Control Which Post Types Are Translatable

The filter takes one argument, the array of post type slugs, and runs each time Lang Forge builds the list, so it also sees product and the LearnDash types that Lang Forge adds itself. Return the array.

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

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

    return $post_types;
});
Example: Filtering the gettext output for a specific language
php
// Override WooCommerce button text for Russian
add_filter('gettext', function ($translation, $text, $domain) {
    if (langforge_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