The codepress_get_lang() WordPress PHP function determines the language to use for CodePress syntax highlighting.
Usage
Here’s a simple example of using the function:
$language = codepress_get_lang('example.html');
In this example, the input is a string representing a filename (‘example.html’). The function will return the language associated with the extension of the filename, which is used for syntax highlighting in CodePress.
Parameters
$filename
(string): The filename used to determine the language for syntax highlighting.
More information
See WordPress Developer Resources: codepress_get_lang()
This function was implemented in WordPress 3.0. It is not deprecated and is still actively used. The source code can be found in the wp-admin/includes/misc.php
file in the WordPress codebase. The related function is codepress_footer_js()
.
Examples
Determine Language of an HTML File
This function gets the language associated with an HTML file for CodePress syntax highlighting.
$language = codepress_get_lang('index.html'); // $language now holds 'html'
Determine Language of a PHP File
This function gets the language associated with a PHP file for CodePress syntax highlighting.
$language = codepress_get_lang('functions.php'); // $language now holds 'php'
Determine Language of a CSS File
This function gets the language associated with a CSS file for CodePress syntax highlighting.
$language = codepress_get_lang('style.css'); // $language now holds 'css'
Determine Language of a JS File
This function gets the language associated with a JavaScript file for CodePress syntax highlighting.
$language = codepress_get_lang('script.js'); // $language now holds 'javascript'
Use with Unknown File Types
If the function is used with an unknown file type, it will return an empty string.
$language = codepress_get_lang('data.xyz'); // $language now holds an empty string ''