Below, you’ll find a detailed guide on how to add the WP Matterport 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 Matterport Shortcode Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the WP Matterport Shortcode Plugin and the shortcodes it provides:
"WP Matterport Shortcode is a dynamic plugin that allows you to easily integrate and display Matterport Showcase content on your WordPress site using shortcodes."
- [matterport]
WP Matterport [matterport] Shortcode
The Shortcode-Gallery-For-Matterport-Showcase plugin shortcode is designed to embed a 3D virtual tour from Matterport into a WordPress site. It allows customization of the tour display, including size, visibility, user interface, zooming, and more.
Shortcode: [matterport]
Parameters
Here is a list of all possible matterport shortcode parameters and attributes:
embed
– Enables the embed mode for the tour.window
– Specifies target window where the tour opens.address
– Displays the address of the location if available.showstats
– Displays statistics of the tour e.g., number of scans.nocache
– Disables caching of the tour data.cols
– Specifies the number of columns for the gallery layout.label
– Sets the label for the tour.welcome
– Sets the welcome message for the tour.width
– Sets the width of the tour display.height
– Sets the height of the tour display.help
– Enables the help guide for the tour.qs
– Determines if the tour starts automatically.brand
– Toggles the display of the Matterport brand.title
– Sets the title for the tour.showdate
– Displays the creation or modification date of the tour.src
– Specifies the source URL of the tour.admin
– Enables the admin mode for the tour.
Examples and Usage
Basic example – Embedding a Matterport 3D tour using the shortcode and the tour’s unique ID.
[matterport src="YourMatterportTourID" /]
Advanced examples
Embedding a Matterport 3D tour with a specified width and height, and setting the tour to autoplay upon page load.
[matterport src="YourMatterportTourID" width="800" height="600" qs="1" /]
Embedding a Matterport 3D tour with additional parameters to hide the help button, disable zooming, and set a specific language.
[matterport src="YourMatterportTourID" help="0" nozoom="1" lang="en" /]
Embedding a Matterport 3D tour with the ’embed’ attribute which allows the tour to be embedded directly into the page, rather than opening in a new window or overlay.
[matterport src="YourMatterportTourID" embed="1" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [matterport]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'matterport', 'matterport_embed_shortcode' );
Shortcode PHP function:
function matterport_embed_shortcode( $atts ) {
$date_format = get_option('date_format');
// Attributes
extract( shortcode_atts(
array(
// Plugin Related
'embed' => NULL, // Added v1.9
'window' => NULL,
'address' => NULL,
'showstats' => NULL,
'nocache' => NULL,
'cols' => 1,
'label' => NULL,
'welcome' => NULL,
'width' => NULL,
'height' => NULL,
// Launching 3D Showcase
'help' => NULL,
'hl' => NULL,
// 'nt' => NULL, -- NO NEED TO SUPPORT
// 'play' => NULL, -- NO NEED TO SUPPORT
'qs' => NULL,
'ts' => NULL,
// Visibility
'brand' => NULL,
'dh' => NULL, // Added v1.7.1
'gt' => NULL, // Added v1.7.1
'hr' => NULL, // Added v1.7.1
'mls' => NULL,
'mt' => NULL, // Added v1.7.1
'portal' => NULL, // Added v2.1
'pin' => NULL, // Added v2.1
// User Interface
'f' => NULL,
'lang' => NULL,
'guides' => NULL,
'hhl' => NULL,
'kb' => NULL,
'lp' => NULL,
'mf' => NULL,
'st' => NULL,
'title' => NULL,
'tourcta' => NULL,
// VR
'vr' => NULL,
'vrcoll' => NULL,
'wh' => NULL,
'showdate' => NULL,
'src' => '',
// Other
'start' => NULL,
'showcase_version' => NULL,
'admin' => NULL,
'nozoom' => NULL,
'maxzoom' => NULL,
'minzoom' => NULL,
'zoomtrans' => NULL,
// PREMIUM
'mpu' => NULL,
'mpv' => NULL,
'mpembed' => NULL,
// MPEmbed
'details' => NULL,
'hdir' => NULL,
'mdir' => NULL,
'stats' => NULL,
'compactdetails' => NULL,
'mdirsearch' => NULL,
'openmt' => NULL,
'logo' => NULL,
'image' => NULL,
'minimap' => NULL,
'minimapurl' => NULL,
'minimaptags' => NULL,
'minimaprotation' => NULL,
'minimapsetrotation' => NULL,
'minimapnopano' => NULL,
'fadehotspots' => NULL,
'hotspots' => NULL,
'filter' => NULL,
'minimapfilter' => NULL,
'bgmusic' => NULL,
'bgmusicloop' => NULL,
'bgmusicvol' => NULL,
'bgmusicpaused' => NULL,
'bgmusicpauseonmedia' => NULL,
'nofade' => NULL,
'scaleui' => NULL,
'tint' => NULL,
'spaces' => NULL,
'reels' => NULL, // deprecated
'copyright' => NULL,
'ga' => NULL,
'aa' => NULL,
'c' => NULL
), $atts )
);
if (substr_count($src,','))
$tours = explode(',',$src);
else
$tours = array($src);
if (($title != NULL && strlen($title) > 1) || $label != NULL) {
// Backwards compatibility with v1.7 and before
if ($label == NULL)
$label = esc_html($title);
if (substr_count($label,';'))
$titles = explode(';',$label);
else
$titles = array($label);
}
ob_start();
?>
<div class="wpm-gallery">
<?php
$i = 0;
$link = "";
$params = "";
// Plugin Related
if ($width!=NULL && $height !=NULL)
$height = NULL;
// Launching a 3D Showcase
if ($help!=NULL && ($help == 1 || $help == 0 || $help == 2))
$params .= '&help=' . $help;
if ($hl!=NULL && ($hl == 1 || $hl == 0))
$params .= '&hl=' . $hl;
if ($hhl!=NULL && ($hhl == 1 || $hhl == 0)) // Undocumented
$params .= '&hhl=' . $hhl;
if ($qs!=NULL && ($qs == 0 || $qs == 1))
$params .= '&qs=' . $qs;
if ($ts!=NULL)
$params .= '&ts=' . preg_replace("/[^0-9,.]/", "", $ts);
// Play omitted
// Visibility
if ($brand!=NULL && ($brand == 1 || $brand == 0))
$params .= '&brand=' . $brand;
// Undocumented
if ($title!=NULL && ($title == 1 || $title == 0 || $title == 2))
$params .= '&title=' . $title;
if ($dh!=NULL && $dh == 0) // Added 1.7.1
$params .= '&dh=0';
if ($gt!=NULL && $gt == 0) // Added 1.7.1
$params .= '&gt=0';
if ($hr!=NULL && $hr == 0) // Added 1.7.1
$params .= '&hr=0';
if ($mls!=NULL && ($mls == 1 || $mls == 2))
$params .= '&mls=' . $mls;
if ($mt!=NULL && $mt == 1)
$params .= '&mt=1';
if ($pin!=NULL && $pin == 0) // Added 1.7.1
$params .= '&pin=0';
if ($portal!=NULL && $portal == 0) // Added 1.7.1
$params .= '&portal=0';
// User Interface
if ($f!=NULL && $f == 0)
$params .= '&f=0';
if ($lang != NULL)
$params .= '&lang=' . $lang;
if ($wh!=NULL && ($wh == 1 || $wh == 0))
$params .= '&wh=' . $wh;
// Zooming
if ($nozoom!=NULL && $nozoom == 1)
$params .= '&nozoom=1';
if ($maxzoom!=NULL)
$params .= '&maxzoom=' . $maxzoom;
if ($minzoom!=NULL)
$params .= '&minzoom=' . $minzoom;
if ($zoomtrans!=NULL && ($zoomtrans == 1 || $zoomtrans == 0))
$params .= '&zoomtrans=' . $zoomtrans;
// Guided Tours
if ($guides!=NULL && $guides == 0)
$params .= '&guides=0';
if ($kb!=NULL && $kb == 0)
$params .= '&kb=' . $kb;
if ($lp!=NULL && $lp == 0)
$params .= '&lp=' . $lp;
if ($mf!=NULL && $mf == 0)
$params .= '&mf=0';
if ($st!=NULL && ($st > 0 && is_int($st)))
$params .= '&st=' . $st;
if ($tourcta!=NULL && ($tourcta == 0 || $tourcta == 2))
$params .= '&tourcta=' . $tourcta;
// Virtual Reality
if ($vr!=NULL && $vr == 0)
$params .= '&vr=0';
if ($vrcoll!=NULL && $vrcoll == 1)
$params .= '&vrcoll=1';
// MPEmbed
$ismpembed = array(
'details','minimap','mdir','hdir','mdirsearch','copyright','logo','image','minimapurl','reels','spaces','nofade','ga', 'aa', 'filter','minimapfilter','fadehotspots','hotspots','tint','c','mpv','mpu','stats',
'minimapnopano', 'minimaprotation', 'minimapsetrotation', 'minimaptags',
'bgmusic', 'bgmusicloop', 'bgmusicvol', 'bgmusicpaused', 'bgmusicpauseonmedia',
'compactdetails', 'openmt'
);
if ($mpu!=NULL && strlen($mpu) <= 4 && is_numeric($mpu))
$params .= '&mpu=' . $mpu;
if ($mpv!=NULL && strlen($mpv) <= 10)
$params .= '&mpv=' . $mpv;
if ($details!=NULL && ($details == 1 || $details == 2 || $details == 3))
$params .= '&details=' . $details;
if ($minimap!=NULL && ($minimap == 1 || $minimap == 2 || $minimap == 3))
$params .= '&minimap=' . $minimap;
if ($mdir!=NULL && ($mdir == 1 || $mdir == 2 || $mdir == 3))
$params .= '&mdir=' . $mdir;
if ($hdir!=NULL && ($hdir == 1 || $hdir == 2 || $hdir == 3))
$params .= '&hdir=' . $hdir;
if ($stats!=NULL && is_int($stats))
$params .= '&stats=' . $stats;
if ($mdirsearch!=NULL && $mdirsearch == 1)
$params .= '&mdir=' . $mdirsearch;
if ($copyright!=NULL && strlen($copyright) > 5)
$params .= '&copyright=' . str_replace(" ","%20",$copyright);
if ($logo!=NULL && strlen($logo) > 5)
$params .= '&logo=' . urlencode($logo);
if ($image!=NULL && strlen($image) > 5)
$params .= '&image=' . urlencode($image);
if ($compactdetails!=NULL && ($compactdetails == 1))
$params .= '&compactdetails='.$compactdetails;
if ($openmt!=NULL && strlen($openmt) == 11)
$params .= '&openmt='.$openmt;
// BG Music
if ($bgmusic!=NULL && strlen($bgmusic) > 5)
$params .= '&bgmusic=' . urlencode($bgmusic);
if ($bgmusicloop!=NULL && $bgmusicloop == 1)
$params .= '&bgmusicloop=1';
if ($bgmusicvol!=NULL && is_numeric($bgmusicvol) && $bgmusicvol > 0.1 && bgmusic <= 1)
$params .= '&bgmusicvol=' . $bgmusicvol;
if ($bgmusicpaused!=NULL && $bgmusicpaused == 1)
$params .= '&bgmusicpaused=1';
if ($bgmusicpauseonmedia!=NULL && $bgmusicpauseonmedia == 1)
$params .= '&bgmusicpauseonmedia=1';
// Minimap
if ($minimapurl!=NULL && strlen($minimapurl) > 5)
$params .= '&minimapurl=' . urlencode($minimapurl);
if ($minimaprotation!=NULL && strlen($minimaprotation) > 5)
$params .= '&stats=' . $stats;
if ($minimapsetrotation!=NULL && is_int($minimapsetrotation) && $minimapsetrotation > 0 && $minimapsetrotation < 360)
$params .= '&minimapsetrotation=' . $minimapsetrotation;
if ($minimaptags!=NULL && $minimaptags == 1)
$params .= '&minimaptags=1';
if ($minimapfilter!=NULL && strlen($minimapfilter) >= 5)
$params .= '&minimapfilter=' . $minimapfilter;
if ($minimapnopano!=NULL && $minimapnopano == 1)
$params .= '&minimapnopano=' . $minimapnopano;
if ($fadehotspots!=NULL && $fadehotspots == 1)
$params .= '&fadehotspots=' . $fadehotspots;
if ($hotspots!=NULL && $hotspots == 2)
$params .= '&hotspots=' . $hotspots;
// Reels / Spaces
if ($reels!=NULL && substr_count(",",$reels) > 1)
$params .= '&reels=' . $reels;
if ($spaces!=NULL && substr_count(",",$spaces) > 1)
$params .= '&spaces=' . $spaces;
if ($nofade!=NULL && $nofade == 1)
$params .= '&nofade=' . $nofade;
if ($ga!=NULL && strlen($ga) >= 14)
$params .= '&ga=' . $ga;
if ($aa!=NULL && strlen($aa) >= 8)
$params .= '&aa=' . $aa;
if ($filter!=NULL && strlen($filter) >= 5)
$params .= '&filter=' . $filter;
if ($tint!=NULL && strlen($tint) == 6)
$params .= '&tint=' . $tint;
if ($c!=NULL && $c == 'cn')
$params .= '&c=' . $c;
// Advanced
if (count($tours) > 1 && $start!=NULL)
$params .= '&start=' . $start;
foreach ($tours as $src) {
if (strlen($src) == 0)
continue;
$src = str_replace("https://my.matterport.com/show/?m=", "", $src);
$src = str_replace("https://mpembed.com/show/?m=", "", $src);
$link = 'https://my.matterport.com/show/?m=' . $src . $params;
if ($showcase_version != NULL && $showcase_version == 3)
$link = str_replace('/show/','/showcase-beta/', $link);
// Auto Enable MPEmbed if parameters are used.
$mpembed = 0;
foreach($ismpembed as $var) {
if (isset($$var))
$mpembed = 1;
}
if ($mpembed == 1)
$link = str_replace('https://my.matterport.com/show/?m=', 'https://mpembed.com/show/?m=', $link);
// Mitigate Cross Site Scripting (XSS) vulnerability by refusing // and " in src param
//echo "[src ".$src."]";
if (strpos($src, '//') !== false || strpos($src, '"') !== false)
continue;
// Extract Space ID
$spaceid = substr($src, 0, 11);
if (!ctype_alnum($spaceid)){ //make sure $spaceid is alphanumeric only
$spaceid = '';
}
//echo "[spaceid ".$spaceid."]";
// Let's see if we have the data cached in the database...
global $wpdb;
$query = 'SELECT data from ' . $wpdb->prefix . 'wpms WHERE name="' . esc_html($src) .'" LIMIT 1';
$cachedTour = $wpdb->get_var( $query );
// Pull JSON object from WordPress Transients as array
if (strlen($cachedTour) > 1)
$thisTour = json_decode($cachedTour, TRUE);
// Otherwise, let's go and find it!
else {
// Connect to JSON Feed
$json = 'https://my.matterport.com/api/v1/player/models/' . $spaceid . '/?format=json';
if (function_exists("curl_init")) {
$curl_options = array(
CURLOPT_URL => $json,
CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_TIMEOUT => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_ENCODING => 'gzip,deflate',
);
$ch = curl_init();
curl_setopt_array( $ch, $curl_options );
$output = curl_exec( $ch );
curl_close($ch);
$arr = json_decode($output,true);
$values = array("name","address","contact_name","contact_phone","formatted_contact_phone","contact_email");
foreach($values as $value) {
if (isset($arr[$value]))
$thisTour[$value] = $arr[$value];
else
$thisTour[$value] = "";
}
$thisTour["nodes"] = (isset($arr['sweeps']) ? count($arr['sweeps']) : 0);
$thisTour["player_options"] = (isset($arr['player_options']) ? $arr['player_options'] : "");
$thisTour["is_vr"] = (isset($arr['is_vr']) ? $arr['is_vr'] : false);
$thisTour["created"] = (isset($arr["created"]) ? $arr["created"] : "");
$thisTour["modified"] = (isset($arr["modified"]) ? $arr["modified"] : "");
}
$thisTour["image"] = 'http://my.matterport.com/api/v1/player/models/' . $spaceid . '/thumb';
// Save data to WordPress to cache for next time...
$jsonData = json_encode($thisTour);
$table_name = $wpdb->prefix . 'wpms';
if ($thisTour != null) {
if (!($wpdb->insert( $table_name,
array(
'time' => (isset($arr["created"]) ? $arr["created"] : ""),
'name' => $src,
'data' => $jsonData
)
))) {
unset($thisTour);
}
}
}
?>
<div class="wpm<?php
if ($cols > 1 && is_numeric($cols))
echo ' wpm-cols' . $cols;
?>">
<?php
if (!isset($thisTour)) {
?>
<div class="wpm-img" style="color: #fff; padding: 10px; font-size: 10px">
Private or invalid tour id: <?php echo esc_html($src) ?>
</div>
<?php
}
else {
// --
// If title parameter is used in shortcode ...
if (isset($titles[$i]) && strlen($titles[$i]) > 2) {
$thisTour["name"] = esc_html($titles[$i]);
if (strlen($thisTour["name"]) < 1)
$thisTour["name"] = "hidden";
}
// if width / height parameters not present, default is 960 x 540 - but if cols > 1, default to 640 x 360
if ($width == NULL && $height == NULL) {
if ($cols != 1)
$width = 640;
else
$width = 960;
}
if (!is_numeric($width)){
if ($cols != 1)
$width = 640;
else
$width = 960;
}
if (!is_numeric($height)){
$height = NULL;
}
$thisTour["image"] = '//my.matterport.com/api/v1/player/models/' . $spaceid . '/thumb/';
if ($height != NULL)
$thisTour["image"] .= '?height=' . $height;
else
$thisTour["image"] .= '?width=' . $width;
$class = 'wpm-tour wpm' . $src;
if ($window == NULL && $embed == NULL) {
$class .= ' wpm-overlay';
}
if ($embed != NULL) {
$class .= ' wpm-embedded';
}
if ($window != NULL && !preg_match('/^[A-Za-z0-9_]+$/',$window)){
$window = NULL;
}
?>
<div class="wpm-img">
<?php if ($embed != NULL) { ?>
<a href="#" data-width="<?php echo $width ?>" data-src="<?php echo esc_url($link) ?>&play=1" class="<?php echo $class ?>"
<?php } else {?>
<a href="<?php echo esc_url($link) ?>&play=1" class="<?php echo $class ?>"
<?php
}
if ($window != NULL)
echo ' target="' . $window . '"';
?>>
<img src="<?php echo $thisTour["image"] ?>" />
<b>►</b>
<i><?php
if (isset($welcome) && strlen($welcome) > 2)
echo esc_html($welcome);
else
_e('Explore 3D Space', 'wp-matterport');
?></i>
</a>
</div>
<div class="wpm-info">
<?php
if ($thisTour["name"] != "hidden") {
?>
<span class="wpm-title"><a class="<?php echo ($window ? 'wpm-overlay ' : '')?>wpm-tour" href="<?php echo esc_url($link) ?>&play=1<?php
if ($window != NULL)
echo '" target="' . $window;
?>"><?php echo $thisTour["name"] ?></a></span>
<?php
}
if (isset($thisTour["address"]) && $address!=NULL) {
if (!is_array($thisTour["address"]))
$thisAddress = json_decode($thisTour["address"]);
else
$thisAddress = (object) $thisTour["address"];
?>
<div class="wpm-address" itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">
<?php
if (strlen($thisAddress->address_1) > 2) {
?>
<span class="wpm-street" itemprop="streetAddress"><?php
echo $thisAddress->address_1;
if (isset($thisAddress->address_2) && strlen($thisAddress->address_2) > 2)
echo '<span>' . $thisAddress->address_2 . '</span>';
?></span>
<?php
}
if (isset($thisAddress->city) && strlen($thisAddress->city) > 2)
echo "\t\t\t\t\t\t<span class='wpm-city' itemprop='addressLocality'>" . $thisAddress->city . "</span>\n";
if (isset($thisAddress->state) && strlen($thisAddress->state) > 2)
echo "\t\t\t\t\t\t<span class='wpm-state' itemprop='addressRegion'>" . $thisAddress->state . "</span>\n";
if (isset($thisAddress->zip) && strlen($thisAddress->zip) > 2)
echo "\t\t\t\t\t\t<span class='wpm-zip' itemprop='postalCode'>" . $thisAddress->zip . "</span>\n";
?>
</div>
<?php
}
if ($showstats!=NULL && isset($thisTour["nodes"])) {
echo "\t\t\t\t\t<span class=\"wpm-nodes\">\n";
echo "\t\t\t\t\t\t<span class=\"wpm-scans\">" . $thisTour["nodes"] . " ";
_e('Scans','wp-matterport');
echo "</span>\n";
if (isset($thisTour["floors"]) && $thisTour["floors"] > 1) {
echo "\t\t\t\t\t\t<span class=\"wpm-floors\">" . $thisTour["floors"];
_e('Floors','wp-matterport');
echo "</span>\n";
}
echo "\t\t\t\t\t</span>\n";
}
if ($showdate != NULL) {
if ($showdate == 'modified')
echo "\t\t\t\t\t" . '<div class="wpm-date">' . __('Last modified','wp-matterport') . ': ' . date($date_format,strtotime($thisTour["modified"])) . '</div>';
else
echo '<div class="wpm-date">' . __('Created', 'wpst modified: ','wp-matterport') . ': ' . date($date_format,strtotime($thisTour["created"])) . '</div>';
}
echo "\t\t\t\t</div>\n";
}
echo "\t\t\t</div>\n";
$i++;
if ($admin != NULL) {
?>
<div style="text-align: center">
<a href="<?php echo esc_url($_SERVER["PHP_SELF"]) ?>?page=wpms-options&refresh=<?php echo esc_url($src) ?>"><?php _e('Reload Thumbnail / Information','wp-matterport'); ?></a> |
<a href="https://my.matterport.com/models/<?php echo esc_url($src) ?>" target="_blank"><?php _e('MyMatterport','wp-matterport'); ?></a>
</div>
<?php
}
}
echo "\t\t</div>\n";
return ob_get_clean();
}
Code file location:
shortcode-gallery-for-matterport-showcase/shortcode-gallery-for-matterport-showcase/wp-matterport.php
Conclusion
Now that you’ve learned how to embed the WP Matterport 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.
Leave a Reply