Embedpress Shortcodes

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

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

Plugin Icon
EmbedPress – Embed PDF, YouTube, Google Docs, Vimeo, Wistia Videos, Audios, Maps & Any Documents in Gutenberg & Elementor

"EmbedPress is a dynamic plugin that allows easy embedding of PDFs, YouTube, Google Docs, Vimeo, Wistia Videos, Audios, Maps & more in Gutenberg & Elementor on your WordPress site."

★★★★☆ (171) Active Installs: 80000+ Tested with: 6.3.2 PHP Version: 5.6
Included Shortcodes:
  • [EMBEDPRESS_SHORTCODE]
  • [embedpress_pdf]
  • [embedpress_calendar]

Embedpress [EMBEDPRESS_SHORTCODE] Shortcode

The EmbedPress shortcode is a powerful tool that dynamically resizes embedded content. It uses plugin settings to define default width and height while also allowing for custom dimensions. This shortcode also includes a ‘powered_by’ attribute, which can be toggled on or off based on the plugin settings. It then parses the content and returns the embedded object.

Shortcode: [EMBEDPRESS_SHORTCODE]

Parameters

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

  • width – sets the width of the embedded content
  • height – sets the height of the embedded content
  • powered_by – displays a ‘powered by’ message if set to ‘yes’

Examples and Usage

Basic example – In the following example, we are using the EmbedPress shortcode to embed a content. The content to be embedded is passed as a parameter within the shortcode.

[EMBEDPRESS_SHORTCODE url="https://www.youtube.com/watch?v=dQw4w9WgXcQ" /]

Advanced examples

In this example, we are using the EmbedPress shortcode to embed a content, but with additional parameters. Here, we are specifying the width and height of the embedded content. If the global embed resize setting is enabled in the plugin, these width and height values will override the default values set in the plugin settings.

[EMBEDPRESS_SHORTCODE url="https://www.youtube.com/watch?v=dQw4w9WgXcQ" width="500" height="300" /]

In the next example, we are using the EmbedPress shortcode to embed a content, but with an additional ‘powered_by’ parameter. This parameter will display a ‘powered by EmbedPress’ message at the bottom of the embedded content, if it is set to ‘yes’.

[EMBEDPRESS_SHORTCODE url="https://www.youtube.com/watch?v=dQw4w9WgXcQ" powered_by="yes" /]

Remember, these shortcodes can be used in any post or page within your WordPress site to embed content using the EmbedPress plugin.

PHP Function Code

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

Shortcode line:

add_shortcode(EMBEDPRESS_SHORTCODE, ['\\EmbedPress\\Shortcode', 'do_shortcode']);

Shortcode PHP function:

function do_shortcode($attributes = [], $subject = null)
    {
        $plgSettings = Core::getSettings();


        $default = [];
        if ($plgSettings->enableGlobalEmbedResize) {
            $default = [
                'width'  => $plgSettings->enableEmbedResizeWidth,
                'height' => $plgSettings->enableEmbedResizeHeight,
                'powered_by' => !empty($plgSettings->embedpress_document_powered_by) ? $plgSettings->embedpress_document_powered_by : 'no',
            ];
        }
        $attributes = wp_parse_args($attributes, $default);
        $embed = self::parseContent($subject, true, $attributes);

        return is_object($embed) ? $embed->embed : $embed;
    }

Code file location:

embedpress/embedpress/EmbedPress/Shortcode.php

Embedpress [embedpress_pdf] Shortcode

The EmbedPress PDF shortcode enables the embedding of PDF files in WordPress posts. It adjusts the width and height based on plugin settings and supports custom color themes.

Shortcode: [embedpress_pdf]

Parameters

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

  • width – Defines the width of the embedded PDF.
  • height – Determines the height of the embedded PDF.
  • powered_by – If set to ‘yes’, shows ‘Powered by EmbedPress’ text.
  • theme_mode – If set to ‘custom’, uses custom color settings.
  • custom_color – Sets the color of the PDF embed if theme_mode is ‘custom’.

Examples and Usage

Basic example – Display a PDF file using the EmbedPress PDF shortcode.

[embedpress_pdf url="https://example.com/sample.pdf" /]

Here, we have used the ’embedpress_pdf’ shortcode to embed a PDF document from a specified URL.

Advanced examples

Embedding a PDF file with custom width and height:

[embedpress_pdf url="https://example.com/sample.pdf" width="600" height="800" /]

In this example, we have used the ‘width’ and ‘height’ attributes to specify the dimensions of the embedded PDF document.

Embedding a PDF file with a custom color theme and a ‘Powered by EmbedPress’ footer:

[embedpress_pdf url="https://example.com/sample.pdf" theme_mode="custom" custom_color="#ff0000" powered_by="yes" /]

This example demonstrates the use of ‘theme_mode’, ‘custom_color’, and ‘powered_by’ attributes. The ‘theme_mode’ attribute is set to ‘custom’ to allow the use of a custom color scheme, defined by the ‘custom_color’ attribute. The ‘powered_by’ attribute is set to ‘yes’ to display a ‘Powered by EmbedPress’ footer below the embedded document.

PHP Function Code

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

Shortcode line:

add_shortcode('embedpress_pdf', ['\\EmbedPress\\Shortcode', 'do_shortcode_pdf']);

Shortcode PHP function:

function do_shortcode_pdf($attributes = [], $subject = null)
    {
        $plgSettings = Core::getSettings();

        $default = [
            'width'  => $plgSettings->enableEmbedResizeWidth,
            'height' => $plgSettings->enableEmbedResizeHeight, 
            'powered_by' => !empty($plgSettings->embedpress_document_powered_by) ? $plgSettings->embedpress_document_powered_by : 'no',
        ];

        if(!empty($plgSettings->pdf_custom_color_settings)){
             $default['theme_mode'] = 'custom';
        }
        if(isset($default['theme_mode']) && $default['theme_mode'] == 'custom' ){
            $default['custom_color'] = $plgSettings->custom_color;
        }

        $attributes = wp_parse_args($attributes, $default);

        $url = preg_replace(
            '/(\[' . EMBEDPRESS_SHORTCODE . '(?:\]|.+?\])|\[\/' . EMBEDPRESS_SHORTCODE . '\])/i',
            "",
            $subject
        );

        ob_start();

        $id = 'embedpress-pdf-shortcode';
        $dimension = "width: {$attributes['width']}px;height: {$attributes['height']}px";
        ?>
            <div class="embedpress-document-embed ose-document <?php echo 'ep-doc-' . md5($id); ?>" style="<?php echo esc_attr($dimension); ?>; max-width:100%; display: block">
                <?php if ($url != '') {
                            if (self::is_pdf($url) && !self::is_external_url($url)) {
                                $renderer = Helper::get_pdf_renderer();
                                $src = $renderer . ((strpos($renderer, '?') == false) ? '?' : '&') . 'file=' . urlencode($url).self::getParamData($attributes);
                                ?>
                        <iframe title="<?php echo esc_attr(Helper::get_file_title($url)); ?>" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true" title="" style="<?php echo esc_attr($dimension); ?>; max-width:100%; display: inline-block" data-emsrc="<?php echo esc_attr($url); ?>" data-emid="<?php echo esc_attr($id); ?>" class="embedpress-embed-document-pdf <?php echo esc_attr($id); ?>" src="<?php echo esc_attr($src); ?>" frameborder="0"></iframe>
                    <?php

                                } else {
                                    ?>
                        <div>
                            <iframe title="<?php echo esc_attr(Helper::get_file_title($url)); ?>" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true" style="<?php echo esc_attr($dimension); ?>; max-width:100%;" src="<?php echo esc_url($url); ?>" data-emsrc="<?php echo esc_attr($url); ?>" data-emid="<?php echo esc_attr($id); ?>" class="embedpress-embed-document-pdf <?php echo esc_attr($id); ?>"></iframe>
                        </div>

                <?php
               
                            }
                            
                            if (!empty($attributes['powered_by']) && $attributes['powered_by'] === 'yes') {
                                printf('<p class="embedpress-el-powered">%s</p>', __('Powered By EmbedPress', 'embedpress'));
                            }
                        }
                        ?>
            </div>

    <?php


            return ob_get_clean();
        }

Code file location:

embedpress/embedpress/EmbedPress/Shortcode.php

Embedpress [embedpress_calendar] Shortcode

The EmbedPress Calendar shortcode is a powerful tool that allows you to embed a highly customizable calendar into your WordPress site. This shortcode enqueues various styles and scripts, setting up the necessary environment for the calendar. It accepts a range of attributes, enabling users to customize the calendar’s appearance and functionality. The attributes control elements such as event pop-ups, event descriptions, event locations, and more. The shortcode also handles calendar IDs and unchecked calendar IDs, allowing for further customization. The final output is a fully functional, customizable calendar embedded into your page.

Shortcode: [embedpress_calendar]

Parameters

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

  • public – Skipped and not included in the shortcode output.
  • filter – Controls the position of the filter, ‘top’ by default.
  • eventpopup – Determines if the event popup should be displayed.
  • eventlink – Determines if the event link should be displayed.
  • hidepassed – Determines if past events should be hidden.
  • hidefuture – Determines if future events should be hidden.
  • eventdescription – Determines if the event description should be displayed.
  • eventlocation – Determines if the event location should be displayed.
  • eventattendees – Determines if the event attendees should be displayed.
  • eventattachments – Determines if the event attachments should be displayed.
  • eventcreator – Determines if the event creator should be displayed.
  • eventcalendarname – Determines if the name of the event calendar should be displayed.
  • calendarids – Comma separated string of calendar ID’s to be displayed.
  • uncheckedcalendarids – Comma separated string of calendar ID’s not to be displayed.
  • fullcalendarconfig – A JSON string that configures the FullCalendar.

Examples and Usage

Basic example – Embed a default calendar on your page using the ’embedpress_calendar’ shortcode.

[embedpress_calendar /]

Advanced examples:

Display calendar with a specific configuration, hiding passed events and showing future events.

[embedpress_calendar hidepassed=true hidefuture=false /]

Customize calendar to show event popup, event link, event description, and event location.

[embedpress_calendar eventpopup=true eventlink=true eventdescription=true eventlocation=true /]

Display specific calendars by specifying their ids.

[embedpress_calendar calendarids="1,2,3" /]

Display a calendar with a custom configuration, using JSON format for the ‘fullcalendarconfig’ attribute.

[embedpress_calendar fullcalendarconfig='{"header": {"left": "prev,next today", "center": "title", "right": "dayGridMonth,timeGridWeek,listWeek"}}' /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'embedpress_calendar', [Embedpress_Google_Helper::class, 'shortcode']);

Shortcode PHP function:

function shortcode($atts = [], $content = null) {

		// When we have no attributes, $atts is an empty string
		if (!is_array($atts)) {
			$atts = [];
		}
		wp_enqueue_style('dashicons');
		wp_enqueue_style( 'fullcalendar');
		wp_enqueue_style( 'fullcalendar_daygrid');
		wp_enqueue_style( 'fullcalendar_timegrid');
		wp_enqueue_style( 'fullcalendar_list');
		wp_enqueue_style( 'epgc');
		wp_enqueue_style( 'tippy_light');


		wp_enqueue_script('popper');
		wp_enqueue_script('tippy');
		wp_enqueue_script('my_moment');
		wp_enqueue_script('my_moment_timezone');
		wp_enqueue_script('fullcalendar');
		wp_enqueue_script('fullcalendar_moment');
		wp_enqueue_script('fullcalendar_moment_timezone');
		wp_enqueue_script('fullcalendar_daygrid');
		wp_enqueue_script('fullcalendar_timegrid');
		wp_enqueue_script('fullcalendar_list');
		wp_enqueue_script('fullcalendar_locales');
		wp_enqueue_script('epgc');
		$defaultConfig = [
			'header' => [
				'left' => 'prev,next today',
				'center' => 'title',
				'right' => 'dayGridMonth,timeGridWeek,listWeek'
			]
		];
		$userConfig = $defaultConfig; // copy
		$userFilter = 'top';
		$userEventPopup = 'true';
		$userEventLink = 'true';
		$userHidePassed = 'false';
		$userHideFuture = 'false';
		$userEventDescription = 'true';
		$userEventLocation = 'true';
		$userEventAttendees = 'false';
		$userEventAttachments = 'false';
		$userEventCreator = 'false';
		$userEventCalendarname = 'false';
		$calendarIds = '';
		$uncheckedCalendarIds = ''; // in filter
		// Get all non-fullcalendar known properties
		foreach ($atts as $key => $value) {
			if ($key === 'public') {
				// This existsed in old versions, but we don't want it in our shortcode output, so skip it.
				continue;
			}
			if ($key === 'filter') {
				$userFilter = $value === 'true' ? 'top' : $value;
				continue;
			}
			if ($key === 'eventpopup') {
				$userEventPopup = $value;
				continue;
			}
			if ($key === 'eventlink') {
				$userEventLink = $value;
				continue;
			}
			if ($key === 'hidepassed') {
				$userHidePassed = $value;
				continue;
			}
			if ($key === 'hidefuture') {
				$userHideFuture = $value;
				continue;
			}
			if ($key === 'eventdescription') {
				$userEventDescription = $value;
				continue;
			}
			if ($key === 'eventattachments') {
				$userEventAttachments = $value;
				continue;
			}
			if ($key === 'eventattendees') {
				$userEventAttendees = $value;
				continue;
			}
			if ($key === 'eventlocation') {
				$userEventLocation = $value;
				continue;
			}
			if ($key === 'eventcreator') {
				$userEventCreator = $value;
				continue;
			}
			if ($key === 'eventcalendarname') {
				$userEventCalendarname = $value;
				continue;
			}
			if ($key === 'uncheckedcalendarids' && !empty($value)) {
				$uncheckedCalendarIds = $value; // comma separated string
				continue;
			}

			if ($key === 'calendarids') {
				if (!empty($value)) {
					$calendarIds = $value; // comma separated string
				}
				continue;
			}
			if ($key === 'fullcalendarconfig') {
				// A JSON string that we can directly send to FullCalendar
				$userConfig = json_decode($value, true);
			} else {
				// Fullcalendar properties that get passed to fullCalendar instance.
				$parts = explode('-', $key);
				$partsCount = count($parts);
				if ($partsCount > 1) {
					$currentUserConfigLayer = &$userConfig;
					for ($i = 0; $i < $partsCount; $i++) {
						$part = $parts[$i];
						if ($i + 1 === $partsCount) {
							if ($value === 'true') {
								$value = true;
							} elseif ($value === 'false') {
								$value = $value;
							}
							$currentUserConfigLayer[$part] = $value;
						} else {
							if (!array_key_exists($part, $currentUserConfigLayer)) {
								$currentUserConfigLayer[$part] = [];
							}
							$currentUserConfigLayer = &$currentUserConfigLayer[$part];
						}
					}
				} else {
					$userConfig[$key] = $value;
				}
			}
		}

		$dataCalendarIds = '';
		if (!empty($calendarIds)) {
			$dataCalendarIds = 'data-calendarids=\'' . json_encode(array_map('trim', explode(',', $calendarIds))) . '\'';
		} else {
			$privateSettingsSelectedCalendarListIds = get_option('epgc_selected_calendar_ids', []);
			if (!empty($privateSettingsSelectedCalendarListIds)) {
				$dataCalendarIds = 'data-calendarids=\'' . json_encode($privateSettingsSelectedCalendarListIds) . '\'';
			}
		}

		$dataUnchekedCalendarIds = '';
		if (!empty($uncheckedCalendarIds)) {
			$dataUnchekedCalendarIds = 'data-uncheckedcalendarids=\'' . json_encode(array_map('trim', explode(',', $uncheckedCalendarIds))) . '\'';
		}

		$filterHTML = '<div class="epgc-calendar-filter" ' . $dataUnchekedCalendarIds . '></div>';

		return '<div class="epgc-calendar-wrapper epgc-calendar-page">' . ($userFilter === 'top' ? wp_kses_post($filterHTML) : '') . '<div '
			. esc_attr($dataCalendarIds) . ' data-filter=\''
			. esc_attr($userFilter) . '\' data-eventpopup=\''
			. esc_attr($userEventPopup) . '\' data-eventlink=\''
			. esc_attr($userEventLink) . '\' data-eventdescription=\''
			. esc_attr($userEventDescription) . '\' data-eventlocation=\''
			. esc_attr($userEventLocation) . '\' data-eventattachments=\''
			. esc_attr($userEventAttachments) . '\' data-eventattendees=\''
			. esc_attr($userEventAttendees) . '\' data-eventcreator=\''
			. esc_attr($userEventCreator) . '\' data-eventcalendarname=\''
			. esc_attr($userEventCalendarname) . '\' data-hidefuture=\''
			. esc_attr($userHideFuture) . '\' data-hidepassed=\''
			. esc_attr($userHidePassed) . '\' data-config=\''
			. json_encode($userConfig) . '\' data-locale="'
			. esc_attr(get_locale())
			. '" class="epgc-calendar"></div>'
			. ($userFilter === 'bottom' ? wp_kses_post($filterHTML) : '')
		. '</div>';
	}

Code file location:

embedpress/embedpress/EmbedPress/ThirdParty/Googlecalendar/Embedpress_Google_Helper.php

Conclusion

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