Mesmerize Companion Shortcodes

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

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

Plugin Icon
Mesmerize Companion

"Mesmerize Companion is a powerful WordPress plugin designed to enhance your website's functionality. It seamlessly integrates with the Mesmerize theme, providing extra customization options and features."

★★★★✩ (51) Active Installs: 90000+ Tested with: 6.3.2 PHP Version: 5.6
Included Shortcodes:
  • []
  • [mesmerize_contact_form]

Mesmerize Companion [null] Shortcode

The Mesmerize Companion plugin shortcode is designed to display the latest news on your WordPress website. The shortcode: [mesmerize_latest_news] fetches recent posts, formats them into columns, and displays them with a read more link. The number of posts and columns can be customized. It ensures seamless integration with your theme to maintain consistency across your site.

Shortcode: [null]

Parameters

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

  • columns – number of columns in the desktop view
  • tablet_columns – number of columns in the tablet view
  • item_class – additional CSS classes for the news item
  • posts – number of posts to display

Examples and Usage

Basic example – A shortcode that will display the latest news posts in a grid format with 4 columns.

[mesmerize_latest_news columns=4]

Advanced examples

Display the latest news posts in a grid format with 6 columns on tablet devices and 4 columns on other devices. The class ‘card y-move bordered’ is applied to each post item.

[mesmerize_latest_news columns=4 tablet_columns=6 item_class="card y-move bordered"]

Display the latest 8 news posts in a grid format with 4 columns. The class ‘card y-move bordered’ is applied to each post item.

[mesmerize_latest_news columns=4 posts=8 item_class="card y-move bordered"]

PHP Function Code

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

Shortcode line:

add_shortcode( 'mesmerize_latest_news', 'mesmerize_companion_latest_news' );

Shortcode PHP function:

function mesmerize_companion_latest_news( $attrs ) {
	ob_start(); ?>
	<?php

	$atts = shortcode_atts(
		array(
			'columns'        => '4',
			'tablet_columns' => '6',
			'item_class'     => 'card y-move bordered',
			'posts'          => '',
		),
		$attrs
	);

	$recentPosts = new WP_Query();

	$cols        = intval( $atts['columns'] );
	$tablet_cols = intval( $atts['tablet_columns'] );

	$post_numbers = ( $atts['posts'] ) ? $atts['posts'] : 12 / $cols;

	add_filter( 'excerpt_length', 'mesmerize_companion_latest_news_excerpt_length' );
	add_filter( 'excerpt_more', 'mesmerize_companion_latest_excerpt_more' );

	?>
	<div class="row center-sm content-left-sm">
		<?php
		$recentPosts->query( 'posts_per_page=' . $post_numbers . ';post_status=publish;post_type=post;ignore_sticky_posts=1;' );
		while ( $recentPosts->have_posts() ) :
			$recentPosts->the_post();
			if ( is_sticky() ) {
				continue;
			}
			$url = get_the_permalink();
			?>
			<div id="post-<?php the_ID(); ?>" class="col-sm-<?php echo esc_attr( $tablet_cols ); ?> col-md-<?php echo esc_attr( $cols ); ?> space-bottom space-bottom-xs">
				<div class="post-content <?php echo esc_attr( $atts['item_class'] ); ?>">
					<?php mesmerize_print_post_thumb(); ?>
					<div class="col-padding col-padding-xs">
						<h3 class="post-title space-bottom-small">
							<a href="<?php echo esc_url( $url ); ?>" rel="bookmark">
								<?php the_title(); ?>
							</a>
						</h3>
						<?php the_excerpt(); ?>
						<a class="read-more link" href="<?php echo esc_url( $url ); ?>">
							<?php echo mesmerize_wp_kses_post( \Mesmerize\Companion::getThemeMod( 'latest_news_read_more', 'Read more' ) ); ?>
						</a>
					</div>
				</div>
			</div>
			<?php
		endwhile;
		wp_reset_postdata();
		?>
	</div>
	<?php
	remove_filter( 'excerpt_length', 'mesmerize_companion_latest_news_excerpt_length' );
	remove_filter( 'excerpt_more', 'mesmerize_companion_latest_excerpt_more' );
	$content = ob_get_contents();
	ob_end_clean();

	return $content;
}

Code file location:

mesmerize-companion/mesmerize-companion/theme-data/mesmerize/functions.php

Mesmerize Companion [mesmerize_contact_form] Shortcode

The Mesmerize Companion shortcode is designed to display a contact form on your website. This shortcode takes in ‘shortcode’ as a parameter. If it’s provided, it decodes the HTML entities and executes the shortcode. If not, it displays a message instructing to set the “contact form shortcode” parameter in the Customizer. The form or message is then returned as content.

Shortcode: [mesmerize_contact_form]

Examples and Usage

Basic example – The following shortcode allows you to add a contact form to your page or post. It uses the ‘mesmerize_contact_form’ shortcode to call the ‘mesmerize_companion_contact_form’ function. If a contact form shortcode is provided in the ‘shortcode’ attribute, it will be displayed. If not, a message will be displayed, prompting you to set a contact form shortcode in the Customizer.

[mesmerize_contact_form shortcode="contact-form-7 id='123' title='Contact form 1'"]

PHP Function Code

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

Shortcode line:

add_shortcode( 'mesmerize_contact_form', 'mesmerize_companion_contact_form' );

Shortcode PHP function:

function mesmerize_companion_contact_form( $attrs = array() ) {
	$atts = shortcode_atts(
		array(
			'shortcode' => '',
		),
		$attrs
	);

	$contact_shortcode = '';
	if ( $atts['shortcode'] ) {
		$contact_shortcode = '[' . html_entity_decode( html_entity_decode( $atts['shortcode'] ) ) . ']';
	}
	ob_start();

	if ( $contact_shortcode !== '' ) {
		echo do_shortcode( $contact_shortcode );
	} else {
		echo '<p style="text-align:center;color:#ababab">' . __( 'Contact form will be displayed here. To activate it you have to set the "contact form shortcode" parameter in Customizer.', 'mesmerize-companion' ) . '</p>';
	}

	$content = ob_get_contents();
	ob_end_clean();

	return $content;
}

Code file location:

mesmerize-companion/mesmerize-companion/theme-data/mesmerize/functions.php

Conclusion

Now that you’ve learned how to embed the Mesmerize Companion 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 *