WP Calameo Shortcode

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

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

Plugin Icon
WP Calameo

"WP Calameo is a robust WordPress plugin that seamlessly integrates Calameo publications into your site. Its user-friendly interface allows easy management and display of online digital docs."

★★✩✩✩ (4) Active Installs: 4000+ Tested with: 6.1.4 PHP Version: false
Included Shortcodes:
  • [calameo]

WP Calameo [calameo] Shortcode

The Calameo shortcode allows you to embed Calameo publications in your WordPress posts or pages. It accepts various attributes to customize the display, such as width, height, language, and more. .

Shortcode: [calameo]

Parameters

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

  • allowminiskin – Enables or disables the mini skin feature.
  • authid – Authentication ID for the Calaméo API.
  • apikey – The API key for authentication.
  • clickto – Defines the action on click. Default is ‘public’.
  • clicktarget – Defines the target of the click action. Default is ‘_self’.
  • clicktourl – URL to redirect when clicked.
  • code – The unique code of the Calaméo book.
  • expires – Expiry date for the Calaméo book link.
  • height – Height of the Calaméo book iframe. Default is ‘400’.
  • hidelinks – Flag to hide or show links. Default is ‘false’.
  • ip – IP address of the user.
  • lang – Language of the Calaméo book.
  • locales – Additional locale settings.
  • mobiledirect – Directs mobile users to a specific URL.
  • mode – Display mode of the Calaméo book.
  • page – Page number to display initially.
  • pagefxopacity – Opacity of the page flip effect.
  • pagefxopacityonzoom – Opacity of the page flip effect on zoom.
  • showsharemenu – Flag to show or hide the share menu.
  • signature – Signature for API authentication.
  • skinurl – URL of the custom skin for the Calaméo book.
  • styleurl – URL of the custom style for the Calaméo book.
  • title – Title of the Calaméo book. Default is ‘View this publication on Calaméo’.
  • url – URL of the Calaméo book.
  • view – View mode of the Calaméo book.
  • volume – Volume level of the Calaméo book.
  • wmode – Window mode of the Calaméo book.
  • width – Width of the Calaméo book iframe. Default is ‘100%’.

Examples and Usage

Basic example – Display a Calaméo publication using its code

[calameo code="1234567890" /]

Advanced examples

Display a Calaméo publication using its code, with a specific language, in mini mode, and with a custom width and height.

[calameo code="1234567890" lang="en" mode="mini" width="240" height="150" /]

Display a Calaméo publication using its code, with a specific language, in viewer mode, with a custom width and height, and with a direct mobile link.

[calameo code="1234567890" lang="en" mode="viewer" width="100%" height="400" mobiledirect="true" /]

Display a Calaméo publication with a specific authid, apikey, and expires parameters for secure viewing.

[calameo code="1234567890" authid="your_authid" apikey="your_apikey" expires="your_expiry_date" /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'calameo', array( $this, 'calameo_shortcode' ) );

Shortcode PHP function:

function calameo_shortcode( $attributes ) {
		$attributes = shortcode_atts(
			array(
				'allowminiskin'       => '',
				'authid'			  => '',
				'apikey'              => '',
				'clickto'             => 'public',
				'clicktarget'         => '_self',
				'clicktourl'          => '',
				'code'                => '',
				'expires'             => '',
				'height'              => '400',
				'hidelinks'           => false,
				'ip'                  => '',
				'lang'				  => '',
				'locales'             => '',
				'mobiledirect'        => '',
				'mode'                => '',
				'page'                => '',
				'pagefxopacity'       => '',
				'pagefxopacityonzoom' => '',
				'showsharemenu'       => '',
				'signature'           => '',
				'skinurl'             => '',
				'styleurl'            => '',
				'title'               => 'View this publication on Calaméo',
				'url'                 => '',
				'view'                => '',
				'volume'              => '',
				'wmode'               => '',
				'width'               => '100%',
			), $attributes, 'calameo'
		);

		$attributes['showsharemenu'] = ( $attributes['showsharemenu'] == '' || $attributes['showsharemenu'] === '1' || $attributes['showsharemenu'] === 'true' ) ? 'true' : 'false';

		// Language
		$language = preg_match( '/^([a-z]+)/i', get_bloginfo( 'language' ), $regs );

		$languages = array(
			'en' => 'en',
			'fr' => 'fr',
			'es' => 'es',
			'de' => 'de',
			'it' => 'it',
			'pt' => 'pt',
			'ru' => 'ru',
		);

		if ( empty( $attributes['lang'] ) && ! empty( $language ) && ! empty( $languages[ $regs[0] ] ) ) {
			$attributes['lang'] = $languages[ $regs[0] ];
		}

		// Prepare viewer and link URLs
		$book_url    = 'http://calameo.com/books/' . $attributes['code'] . ( ! empty( $attributes['authid'] ) ? '?authid=' . $attributes['authid'] : '' );
		$home_url    = 'http://calameo.com';
		$publish_url = 'http://calameo.com/upload';
		$browse_url  = 'http://calameo.com/browse/weekly/?o=7&w=DESC';
		$viewer_url  = '//v.calameo.com/';

		// Preparing Flashvars
		$flashvars  = 'bkcode=' . $attributes['code'];
		$flashvars .= '&language=' . $attributes['lang'];
		$flashvars .= '&page=' . $attributes['page'];
		$flashvars .= '&showsharemenu=' . $attributes['showsharemenu'];

		switch ( $attributes['mode'] ) {
			case 'mini':
				if ( empty( $attributes['width'] ) ) {
					$attributes['width'] = '240';
				}
				if ( empty( $attributes['height'] ) ) {
					$attributes['height'] = '150';
				}
				if ( empty( $attributes['clickto'] ) ) {
					$attributes['clickto'] = 'public';
				}
				if ( empty( $attributes['clicktarget'] ) ) {
					$attributes['clicktarget'] = '_self';
				}
				if ( empty( $attributes['clicktourl'] ) ) {
					$attributes['clicktourl'] = '';
				}
				if ( empty( $attributes['autoflip'] ) ) {
					$attributes['autoflip'] = '0';
				}
				if ( empty( $attributes['wmode'] ) ) {
					$attributes['wmode'] = 'transparent';
				}

				$flashvars .= '&clickTo=' . rawurlencode( $attributes['clickto'] );
				$flashvars .= '&clickTarget=' . rawurlencode( $attributes['clicktarget'] );
				$flashvars .= '&clickToUrl=' . rawurlencode( $attributes['clicktourl'] );
				$flashvars .= '&autoFlip=' . max( 0, intval( $attributes['autoflip'] ) );
				$flashvars .= '&mode=mini';

				break;
			case 'viewer':
				$flashvars .= '&mode=viewer';
				if ( ! empty( $attributes['mobiledirect'] ) ) {
					$flashvars .= '&mobiledirect=' . $attributes['mobiledirect'];
				}
			default:
				if ( empty( $attributes['width'] ) ) {
					$attributes['width'] = '100%';
				}
				if ( empty( $attributes['height'] ) ) {
					$attributes['height'] = '400';
				}

				break;
		}

		if ( ! empty( $attributes['authid'] ) ) {
			$flashvars .= '&authid=' . $attributes['authid'];
		}
		if ( ! empty( $attributes['view'] ) ) {
			$flashvars .= '&view=' . $attributes['view'];
		}
		if ( ! empty( $attributes['wmode'] ) ) {
			$flashvars .= '&wmode=' . $attributes['wmode'];
		}
		if ( ! empty( $attributes['allowminiskin'] ) ) {
			$flashvars .= '&allowminiskin=' . $attributes['allowminiskin'];
		}
		if ( ! empty( $attributes['skinurl'] ) ) {
			$flashvars .= '&skinurl=' . $attributes['skinurl'];
		}
		if ( ! empty( $attributes['styleurl'] ) ) {
			$flashvars .= '&styleurl=' . $attributes['styleurl'];
		}
		if ( ! empty( $attributes['shareurl'] ) ) {
			$flashvars .= '&shareurl=' . $attributes['shareurl'];
		}
		if ( ! empty( $attributes['locales'] ) ) {
			$flashvars .= '&locales=' . $attributes['locales'];
		}
		if ( ! empty( $attributes['volume'] ) ) {
			$flashvars .= '&volume=' . $attributes['volume'];
		}
		if ( ! empty( $attributes['pagefxopacity'] ) ) {
			$flashvars .= '&pagefxopacity=' . $attributes['pagefxopacity'];
		}
		if ( ! empty( $attributes['pagefxopacityonzoom'] ) ) {
			$flashvars .= '&pagefxopacityonzoom=' . $attributes['pagefxopacityonzoom'];
		}
		if ( ! empty( $attributes['ip'] ) ) {
			$flashvars .= '&ip=' . $attributes['ip'];
		}
		if ( ! empty( $attributes['apikey'] ) ) {
			$flashvars .= '&apikey=' . $attributes['apikey'];
		}
		if ( ! empty( $attributes['expires'] ) ) {
			$flashvars .= '&expires=' . $attributes['expires'];
		}
		if ( ! empty( $attributes['signature'] ) ) {
			$flashvars .= '&signature=' . $attributes['signature'];
		}
		// Sizes and units
		$attributes['widthUnit']  = ( strpos( $attributes['width'], '%' ) ) ? '' : 'px';
		$attributes['heightUnit'] = ( strpos( $attributes['height'], '%' ) ) ? '' : 'px';

		// Generate HTML embed code
		$html = '<div style="' . ( empty( $attributes['styles'] ) ? 'text-align: center; width:' . $attributes['width'] . $attributes['widthUnit'] . '; margin: 12px auto;' : $attributes['styles'] ) . '">';

		if ( empty( $attributes['hidelinks'] ) ) {
			$html .= '<div style="margin: 4px 0px;"><a href="' . $book_url . '">' . $attributes['title'] . '</a></div>';
		}

		$html .= '<iframe src="' . $viewer_url . '?' . $flashvars . '" width="' . $attributes['width'] . '" height="' . $attributes['height'] . '" style="width:' . $attributes['width'] . $attributes['widthUnit'] . ';height:' . $attributes['height'] . $attributes['heightUnit'] . '" frameborder="0" scrolling="no" allowtransparency allowfullscreen></iframe>';

		if ( empty( $attributes['hidelinks'] ) ) {
			$html .= '<div style="margin: 4px 0px; font-size: 90%;"><a rel="nofollow" href="' . $publish_url . '">Publish</a> at <a href="' . $home_url . '">Calam&eacute;o</a> or <a href="' . $browse_url . '">browse</a> the library.</div>';
		}

		$html .= '</div>';

		return $html;
	}

Code file location:

wp-calameo/wp-calameo/wp-calameo.php

Conclusion

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