WP Maintenance Shortcode

Below, you’ll find a detailed guide on how to add the WP Maintenance 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 WP Maintenance Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the WP Maintenance Plugin and the shortcodes it provides:

Plugin Icon
WP Maintenance

"WP Maintenance is a must-have WordPress plugin for website owners. It allows you to put your site on maintenance mode, displaying a friendly notice to visitors while you make updates or fixes."

★★★★☆ (86) Active Installs: 40000+ Tested with: 6.2.3 PHP Version: false
Included Shortcodes:
  • [wpm_social]

WP Maintenance [wpm_social] Shortcode

The WP Maintenance shortcode ‘wpm_social’ displays social media icons on your site. It fetches social network settings and lists from WP Maintenance settings. It checks if social networks are enabled and if there’s at least one network. If it’s on mobile, it reduces the icon size. It also provides the option to customize the size and enable/disable the feature.

Shortcode: [wpm_social]

Parameters

Here is a list of all possible wpm_social shortcode parameters and attributes:

  • size – Determines the size of the social media icons.
  • enable – If set to 1, it will display the social media icons.

Examples and Usage

Basic example – The following shortcode displays the social icons with the default size and only if the enable attribute is set in the WP Maintenance settings.

[wpm_social /]

Advanced examples

Display the social icons with a custom size. In this example, the size of the icons is set to 32px.

[wpm_social size=32 /]

Enable the display of social icons even if the enable attribute is not set in the WP Maintenance settings. In this example, the enable attribute is set to 1, which means the social icons will be displayed regardless of the WP Maintenance settings.

[wpm_social enable=1 /]

Display the social icons with a custom size and enable the display of icons regardless of the WP Maintenance settings. In this example, the size of the icons is set to 32px and the enable attribute is set to 1.

[wpm_social size=32 enable=1 /]

PHP Function Code

In case you have difficulties debugging what causing issues with [wpm_social] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'wpm_social', 'wpm_social_shortcode' );

Shortcode PHP function:

function wpm_social_shortcode( $atts ) {

    if(get_option('wp_maintenance_settings_socialnetworks')) { extract(get_option('wp_maintenance_settings_socialnetworks')); }
    $paramSocial = get_option('wp_maintenance_settings_socialnetworks');

    $paramList = get_option('wp_maintenance_list_socialnetworks');
    $countSocial = wpm_array_value_count($paramList);
    
    // Si on est en mobile on réduit les icones
    if ( wp_is_mobile() ) {
        $paramSocial['size'] = 32;
    }

	// Attributes
	extract( shortcode_atts(
		array(
			'size' => 64,
            'enable' => 0
		), $atts )
	);
    if($paramSocial['theme']!='') {
        $srcIcon = get_stylesheet_directory_uri().'/'.esc_html($paramSocial['theme']).'/';
        $iconSize = 'width='.$paramSocial['size'];
    } else {
        $srcIcon = plugin_dir_url( __DIR__ ).'socialicons/'.$paramSocial['style'].'/'.$paramSocial['size'].'/';
        $iconSize = '';
    }
    $contentSocial = '';
    if( isset($paramSocial['enable']) && $paramSocial['enable']==1 && $countSocial>=1) {
         $contentSocial .= '<div id="wpm-social-footer" class="wpm_social"><ul class="wpm_horizontal">';
            foreach($paramList as $socialName=>$socialUrl) {
                if($socialUrl!='') {
                    if( $socialName == 'email' ){
                        $socialUrl = 'mailto:'.esc_html($socialUrl);
                        $texte = __('Send me a', 'wp-maintenance');
                    } else {
                        $socialUrl = esc_url($socialUrl);
                        $texte = esc_html($paramSocial['texte']);
                    }
                    $contentSocial .= '<li><a href="'.$socialUrl.'" target="_blank"><img src="'.esc_url($srcIcon.$socialName).'.png" alt="'.$texte.' '.ucfirst(esc_html($socialName)).'" '.$iconSize.' title="'.$texte.' '.ucfirst(esc_html($socialName)).'" /></a></li>';
                }
            }
         $contentSocial .='</ul></div>';
        return $contentSocial;
     } else {
        // Code
        return '';
    }
}

Code file location:

wp-maintenance/wp-maintenance/includes/shortcodes.php

Conclusion

Now that you’ve learned how to embed the WP Maintenance 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.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *