This page documents the shortcode functionality and automatic content filter that enable users to display language switchers and translation hints within post content. The plugin provides two shortcodes ([sc_msls] and [sc_msls_widget]) and an optional content filter that automatically appends translation availability notices to singular posts and pages.
For information about the underlying output generation system, see Language Switcher Output. For widget and block implementations, see Widgets and Gutenberg Blocks. For programmatic access via theme functions, see Public API Reference.
The plugin provides three mechanisms for displaying language switchers and translation hints within content:
| Method | Class | Display Location | Activation |
|---|---|---|---|
[sc_msls] shortcode | MslsShortCode | Inline within content | Manual insertion |
[sc_msls_widget] shortcode | MslsShortCode | Inline within content | Manual insertion |
| Content filter | MslsContentFilter | Appended to post content | Settings toggle |
All three methods ultimately delegate to MslsOutput::create() for HTML generation, ensuring consistent output formatting across display methods.
Sources: readme.txt35-36 includes/MslsContentFilter.php1-90
Sources: includes/MslsContentFilter.php18-22 MultisiteLanguageSwitcher.php57-62
[sc_msls]The [sc_msls] shortcode provides a simple way to insert language switcher links inline within post or page content.
[sc_msls] This outputs the language switcher with default settings configured in the plugin options.
The shortcode accepts the same parameters as the msls_the_switcher() public API function, passed as shortcode attributes:
[sc_msls before="<div class='languages'>" after="</div>" sep=" | "] Available parameters:
| Parameter | Description | Default |
|---|---|---|
before | HTML markup before the language list | Empty string |
after | HTML markup after the language list | Empty string |
sep | Separator between language links | Empty string |
display | Display format (0-3) | Plugin settings |
The shortcode is registered via MslsShortCode::init() during plugin initialization. When WordPress encounters the shortcode in content, it calls the shortcode handler which:
msls_get_switcher($attr) with the attribute arrayThe msls_get_switcher() function applies the msls_get_output filter to obtain an MslsOutput instance, then calls set_tags($arr) to configure display parameters before rendering.
Sources: MultisiteLanguageSwitcher.php57-62 readme.txt35
[sc_msls_widget]The [sc_msls_widget] shortcode provides an alternative shortcode that displays the language switcher in a widget-like format.
[sc_msls_widget] [sc_msls]Both shortcodes call the same underlying msls_get_switcher() function, but [sc_msls_widget] may apply different default styling or wrapper elements to match widget presentation. The exact behavior depends on the implementation in MslsShortCode class.
Sources: readme.txt36
The content filter provides automatic translation availability hints appended to post and page content without manual intervention.
The content filter is controlled by the is_content_filter() option in plugin settings. When enabled, it automatically appends a notice to singular posts and pages (excluding the front page) informing visitors about available translations.
Sources: includes/MslsContentFilter.php29-35
The MslsContentFilter::init() static method registers the content filter during plugin initialization:
includes/MslsContentFilter.php18-22
This adds the content_filter() method to WordPress's the_content filter hook.
The content_filter() method applies the translation hint conditionally:
includes/MslsContentFilter.php29-35
Conditions for display:
!is_front_page())is_singular())$this->options->is_content_filter())The filter_string() method constructs the HTML notice:
includes/MslsContentFilter.php45-67
Process:
MslsOutput::create()->get(1, true, true) to retrieve available translation linksformat_available_languages()msls_filter_string filter for customization<p id="msls">...</p>)The format_available_languages() method handles grammatical formatting:
includes/MslsContentFilter.php73-88
Formatting rules:
nullSources: includes/MslsContentFilter.php73-88
Developers can customize the entire translation hint output by hooking into the msls_filter_string filter:
includes/MslsContentFilter.php52-61
Filter parameters:
$output (string): The default formatted message$links (array): Array of available translation linksExample usage:
The filter_string() method accepts optional parameters to customize the HTML wrapper:
While these parameters are currently not exposed via filters, they can be modified by extending the MslsContentFilter class.
Sources: includes/MslsContentFilter.php45-67
Both shortcodes and the content filter delegate to MslsOutput for actual HTML generation:
Sources: MultisiteLanguageSwitcher.php57-62
The MslsOutput::get() method accepts three parameters that control output behavior:
includes/MslsContentFilter.php46
| Parameter | Type | Purpose |
|---|---|---|
$display | int | Display format (0-3): flag+desc, flag, desc+flag, desc |
$link | bool | Whether to output as links or plain text |
$excl | bool | Whether to exclude current blog from output |
For shortcodes, these parameters can be specified via shortcode attributes. For the content filter, the values are hardcoded as get(1, true, true) to display flags only as clickable links excluding the current blog.
Sources: includes/MslsContentFilter.php46
The plugin includes comprehensive test coverage for the content filter in TestMslsContentFilter.php:
Test scenarios:
msls_filter_string hookSources: tests/phpunit/TestMslsContentFilter.php25-241
The test for multiple translations verifies correct formatting:
tests/phpunit/TestMslsContentFilter.php124-188
This test mocks three blog objects (Italian, German, French) and verifies the output contains the properly formatted language list: "Italiano, Deutsch and Français".
Sources: tests/phpunit/TestMslsContentFilter.php124-188
The content filter uses WordPress conditional tags to determine when to display:
Conditional checks:
!is_front_page() prevents hints on the home pageis_singular() limits display to single posts/pagesis_content_filter() verifies the feature is enabledSources: includes/MslsContentFilter.php30
The content filter leverages the same caching mechanisms as other display methods:
MslsOutput::get()MslsSqlCacherThe content filter executes on every call to the_content, but early returns minimize overhead:
Sources: includes/MslsContentFilter.php29-35
The content filter contains two translatable strings:
includes/MslsContentFilter.php50
Default English text: "This post is also available in %s."
includes/MslsContentFilter.php85
Default English text: "%1$s and %2$s"
These strings are localized via the multisite-language-switcher text domain and can be translated through WordPress.org's translation system or via PO/MO files.
Sources: includes/MslsContentFilter.php50 includes/MslsContentFilter.php85
For a post available in German and French, the automatic hint appears as:
Sources: readme.txt35-37 includes/MslsContentFilter.php45-67
Refresh this wiki
This wiki was recently refreshed. Please wait 6 days to refresh again.