Mashsharer Shortcodes

Below, you’ll find a detailed guide on how to add the Mashsharer Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Mashsharer Plugin shortcodes not to show or not to work correctly.

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

Plugin Icon
Social Media Share Buttons And Social Buttons | MashShare

"Social Media Share Buttons And Social Buttons | MashShare is a comprehensive plugin that seamlessly integrates social share buttons on your WordPress site. Enhance user engagement and increase your site's visibility with MashSharer."

★★★★☆ (1025) Active Installs: 20000+ Tested with: 6.3.2 PHP Version: 5.6
Included Shortcodes:
  • [mashsb_rwmb_meta]
  • [mashshare]

Mashsharer [mashsb_rwmb_meta] Shortcode

The MashShare plugin shortcode is a function that retrieves and displays custom field values. It’s configured to accept parameters like ‘post_id’ and ‘meta_key’. If ‘meta_key’ is empty, it returns an empty string. It uses these parameters to fetch and return the value of the specified custom field.

Shortcode: [mashsb_rwmb_meta]

Parameters

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

  • post_id – Specifies the unique identifier of the post.
  • meta_key – Determines the specific metadata value to retrieve.

Examples and Usage

Basic example – The shortcode below retrieves the value of a custom field (meta_key) associated with a specific post (post_id). The post ID is automatically generated by the get_the_ID() function.

[mashsb_rwmb_meta meta_key="your_meta_key" /]

Advanced examples

The shortcode below retrieves the value of a custom field (meta_key) associated with a specific post (post_id). The post ID is manually set to a specific value.

[mashsb_rwmb_meta meta_key="your_meta_key" post_id="1234" /]

Another advanced example includes retrieving the value of multiple custom fields (meta_keys) associated with a specific post (post_id). The post ID is manually set to a specific value.

[mashsb_rwmb_meta meta_key="your_meta_key1, your_meta_key2, your_meta_key3" post_id="1234" /]

Remember to replace “your_meta_key”, “your_meta_key1”, “your_meta_key2”, and “your_meta_key3” with the actual meta keys you want to retrieve. Also, replace “1234” with the actual ID of the post you’re interested in.

PHP Function Code

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

Shortcode line:

add_shortcode( 'mashsb_rwmb_meta', 'mashsb_rwmb_meta_shortcode' );

Shortcode PHP function:

function mashsb_rwmb_meta_shortcode( $atts )
	{
		$atts = wp_parse_args( $atts, array(
			'post_id' => get_the_ID(),
		) );
		if ( empty( $atts['meta_key'] ) )
			return '';

		$field_id = $atts['meta_key'];
		$post_id  = $atts['post_id'];
		unset( $atts['meta_key'], $atts['post_id'] );

		return mashsb_rwmb_the_value( $field_id, $atts, $post_id, false );
	}

Code file location:

mashsharer/mashsharer/includes/admin/meta-box/inc/functions.php

Mashsharer [mashshare] Shortcode

The Mashshare shortcode is a powerful tool that allows users to customize social share buttons on their WordPress site. This shortcode enables the display of share counts, the selection of specific social networks, and the alignment of share buttons. It also allows for custom text and URLs to be shared, and the size of the buttons to be adjusted. The shortcode is highly flexible, catering to various design needs and preferences, making social sharing more user-friendly and visually appealing.

Shortcode: [mashshare]

Parameters

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

  • cache – Controls the caching duration in seconds.
  • shares – Determines whether the share count is shown.
  • buttons – Determines whether the share buttons are displayed.
  • services – Sets the number of visible services.
  • align – Positions the share buttons to the left or right.
  • text – Defines the custom text to share.
  • url – Specifies the URL to share.
  • networks – Lists the networks to enable for sharing, separated by commas.
  • size – Sets the size of the share buttons: small, medium, or large.
  • icons – Determines whether icons are shown in the share buttons.

Examples and Usage

Basic example – Display the share count and buttons with default settings.

[mashshare /]

Advanced examples

Display the share count and buttons with custom alignment and size.

[mashshare align="right" size="large" /]

Display the share count only, without the share buttons.

[mashshare shares="true" buttons="false" /]

Display the share buttons for specific networks only.

[mashshare networks="facebook,twitter,linkedin" /]

Use a custom share URL and text.

[mashshare url="https://example.com" text="Check this out!" /]

Control the cache duration for the share count.

[mashshare cache="7200" /]

Display a specific number of visible services.

[mashshare services="3" /]

These examples demonstrate the flexibility of the Mashshare shortcode. By adjusting the parameters, you can control how the share count and buttons are displayed on your website.

PHP Function Code

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

Shortcode line:

add_shortcode('mashshare', 'mashshareShortcodeShow');

Shortcode PHP function:

function mashshareShortcodeShow($args)
{
    global $mashsb_options, $mashsb_custom_url, $mashsb_custom_text;

    $sharecount = '';

    //Filter shortcode args to add an option for developers to change (add) some args
    apply_filters('mashsb_shortcode_atts', $args);

    extract(shortcode_atts(array(
        'cache' => '3600',
        'shares' => 'true',
        'buttons' => 'true',
        'services' => '0', //default is by admin option - plus 1 because array starts counting from zero
        'align' => 'left',
        'text' => '', // $text
        'url' => '', // $url
        'networks' => '', // List of networks separated by comma
        'size' => '', // small, medium, large button size
        'icons' => '0' // 1 
    ), $args));

    // Visible services
    $count_services = !empty($services) ? $services : 0;

    // Enable specific networks
    $networks = !empty($networks) ? explode(",", $networks) : false;

    // Convert into appropriate array structure
    if ($networks) {
        $new = array();
        foreach ($networks as $key => $value) {
            $new[$key]['id'] = $value;
            $new[$key]['status'] = '1';
            $new[$key]['name'] = $value;
        }
        $networks = $new;
    }

    // The global available custom url to share
    $mashsb_custom_url = !empty($url) ? $url : '';
    // local url
    $mashsb_url = empty($url) ? mashsb_get_url() : $url;

    // Define custom text to share
    $mashsb_custom_text = !empty($text) ? $text : false;

    if ($shares != 'false') {
        $sharecount = mashsb_render_sharecounts($mashsb_url, $align, $size);
        // shortcode [mashshare shares="true" buttons="false"] 
        if ($shares === "true" && $buttons === 'false') {
            return $sharecount;
        }
    }

    $class_stretched = isset($mashsb_options['responsive_buttons']) ? 'mashsb-stretched' : '';

    $return = '<aside class="mashsb-container mashsb-main ' . $class_stretched . '">'
        . mashsb_content_above() .
        '<div class="mashsb-box">'
        . $sharecount .
        '<div class="mashsb-buttons">'
        . mashsb_getNetworksShortcode(true, $count_services, $networks, $size, $icons) .
        '</div></div>
                    <div style="clear:both;"></div>'
        . mashsb_subscribe_content()
        . mashsb_content_below() .
        '</aside>
            <!-- Share buttons made by mashshare.net - Version: ' . MASHSB_VERSION . '-->';

    $allowedElements = [
        'aside' => [
            'class' => [],
            'style' => [],
        ],
        'a' => [
            'class' => [],
            'href' => [],
            'title' => [],
            'rel' => [],
            'target' => [],
            'style' => [],
            'data-mashsb-url' => [],
        ],
        'div' => [
            'class' => [],
            'style' => [],
        ],
        'span' => [
            'class' => [],
            'style' => [],
        ],
    ];

    // Allow the style property `display in html output.
    add_filter( 'safe_style_css', function( $styles ) {
        $styles[] = 'display';
        return $styles;
    } );

    return apply_filters('mashsb_output_buttons', wp_kses($return, $allowedElements));
}

Code file location:

mashsharer/mashsharer/includes/template-functions.php

Conclusion

Now that you’ve learned how to embed the Mashsharer Plugin shortcodes, 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 *