Below, you’ll find a detailed guide on how to add the Impressum Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Impressum Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the Impressum Plugin and the shortcodes it provides:
"Impressum is a WordPress plugin designed to seamlessly integrate your site's legal information. With the Impressum plugin, comply effortlessly with mandatory law disclosures. Easy to use and customize!"
- [impressum]
Impressum [impressum] Shortcode
The Impressum shortcode is a powerful tool for customizing your website’s imprint. It renders specific sections based on provided attributes, merging global and local options for maximum flexibility.
The code checks for markup and title output, allowing you to choose whether to display these elements. It also verifies the fields to be displayed, skipping empty or disabled ones. Special conditions apply for ‘press_law_person’ field.
The output is wrapped in a div container if markup is true, providing a neat structure. If not, it simply removes the trailing comma. This makes the Impressum shortcode an efficient solution for imprint customization.
Shortcode: [impressum]
Parameters
Here is a list of all possible impressum shortcode parameters and attributes:
sections
– Specifies the sections of the impressum to be displayed.markup
– Determines if the impressum should be wrapped in a div container.className
– Provides a CSS class to style the impressum.titles
– Controls whether section titles should be displayed.enabledFields
– Specifies which fields of the impressum to display.
Examples and Usage
Basic example – Display the entire Impressum content without any specific sections or fields.
[impressum /]
Advanced examples
Display specific sections of the Impressum content by specifying the ‘sections’ attribute. The sections are separated by commas.
[impressum sections="section1, section2" /]
Display specific fields of the Impressum content by specifying the ‘enabledFields’ attribute. The fields are separated by commas.
[impressum enabledFields="field1, field2" /]
Control the display of markup by setting the ‘markup’ attribute to false. This will output the content without any HTML markup.
[impressum markup="false" /]
Control the display of titles by setting the ‘titles’ attribute to false. This will output the content without any section or field titles.
[impressum titles="false" /]
Combine multiple attributes to control the output of the Impressum content. This example displays specific sections without titles and without HTML markup.
[impressum sections="section1, section2" titles="false" markup="false" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [impressum]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'impressum', [ $this, 'render' ] );
Shortcode PHP function:
function render( $attributes ) {
$attributes = (array) $attributes;
$fields = Helper::get_option( 'impressum_imprint_options', true );
$output = '';
$sections = ( ! empty( $attributes['sections'] ) ? array_map( 'trim', explode( ',', $attributes['sections'] ) ) : [] );
// merge global and local options
if ( ! empty( $fields['default'] ) ) {
$fields_global = $fields['default'];
unset( $fields['default'] );
$fields = array_merge( $fields_global, $fields );
}
// return empty string if there are no fields
if ( empty( $fields ) ) {
return $output;
}
// check for markup output
if ( ! isset( $attributes['markup'] ) ) {
$attributes['markup'] = true;
}
else {
$attributes['markup'] = $attributes['markup'] !== 'false' && boolval( $attributes['markup'] );
}
// check for title output
if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'is-style-no-title' ) !== false ) {
$attributes['titles'] = false;
}
if ( ! isset( $attributes['titles'] ) ) {
$attributes['titles'] = true;
}
else {
$attributes['titles'] = $attributes['titles'] !== 'false' && boolval( $attributes['titles'] );
}
if ( $attributes['markup'] ) {
// open imprint container
$output .= '<div class="impressum__imprint-container">';
}
foreach ( $fields as $field => $value ) {
// check shortcode sections
if ( ! empty( $sections ) && ! in_array( $field, $sections, true ) ) continue;
// check block enabled fields
if ( ! empty( $attributes['enabledFields'] ) && ! in_array( $field, $attributes['enabledFields'], true ) ) continue;
// check whether the field should be displayed
if (
empty( $value )
|| (
! empty( Impressum::get_instance()->settings_fields[ $field ]['no_output'] )
&& Impressum::get_instance()->settings_fields[ $field ]['no_output'] === true
&& ! in_array( $field, $sections, true )
)
) continue;
// special case for press law person, which should only be displayed
// if the checkbox is checked
if ( $field === 'press_law_person' && empty( $fields['press_law_checkbox'] ) ) continue;
$output .= $this->render_field( $field, $value, $attributes, $fields );
}
if ( $attributes['markup'] ) {
// close imprint container
$output .= '</div>';
}
else {
// remove trailing comma
$output = rtrim( $output, ', ' );
}
return $output;
}
Code file location:
impressum/impressum/inc/class-frontend.php
Conclusion
Now that you’ve learned how to embed the Impressum Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply