Below, you’ll find a detailed guide on how to add the WP Meta SEO 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 WP Meta SEO Plugin shortcodes not to show or not to work correctly.
Before starting, here is an overview of the WP Meta SEO Plugin and the shortcodes it provides:
"WP Meta SEO is a powerful plugin designed to optimize your WordPress site's SEO. With this tool, you can easily manage all your meta information, generate sitemaps, add Google Analytics tracking, and much more."
- [wpms_html_sitemap]
- [wpms_breadcrumb]
WP Meta SEO [wpms_html_sitemap] Shortcode
The ‘wpms_html_sitemap’ shortcode generates a dynamic HTML sitemap for your WordPress website. It fetches public post types excluding built-in ones. It provides three themes: ‘default’, ‘tab’, and ‘accordions’, each with unique styles and scripts.
Shortcode: [wpms_html_sitemap]
Examples and Usage
Basic example – Display a default HTML sitemap on your WordPress website.
[wpms_html_sitemap /]
PHP Function Code
In case you have difficulties debugging what causing issues with [wpms_html_sitemap]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('wpms_html_sitemap', array($this, 'sitemapShortcode'));
Shortcode PHP function:
function sitemapShortcode()
{
$html = '';
// include style
if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
$theme = $this->settings_sitemap['wpms_html_sitemap_theme'];
} else {
$theme = 'default';
}
$custom_post_types = get_post_types(
array(
'public' => true,
'exclude_from_search' => false,
'_builtin' => false
)
);
if ($theme === 'default') {
wp_enqueue_style(
'html-sitemap',
plugins_url('assets/css/html_sitemap.css', dirname(__FILE__)),
array(),
WPMSEO_VERSION
);
$html = $this->sitemapThemeDefault();
} elseif ($theme === 'tab') {
wp_enqueue_script(
'wpms_tabs_js',
plugins_url('assets/js/wpms-tabs.js', dirname(__FILE__)),
array('jquery'),
WPMSEO_VERSION,
true
);
wp_enqueue_style(
'wpms_materialize_style',
plugins_url('assets/css/materialize/materialize_frontend_tab_theme.css', dirname(__FILE__)),
array(),
WPMSEO_VERSION
);
echo '<div id="wpms_sitemap" class="theme_tab">';
require_once(WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/theme/tab/menu_bar.php');
require_once(WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/theme/tab/source_posts.php');
require_once(WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/theme/tab/source_pages.php');
if (!empty($this->settings_sitemap['wpms_sitemap_customUrl'])) {
require_once(WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/theme/tab/source_urlcustom.php');
}
// source menu
$ids_menu = array(0);
$check_menu = array();
$terms = get_terms(array('taxonomy' => 'nav_menu', 'hide_empty' => true));
foreach ($terms as $term) {
$list_submenu_id = get_objects_in_term($term->term_id, 'nav_menu');
$ids_menu = array_merge($ids_menu, $list_submenu_id);
}
if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
$this->settings_sitemap['wpms_sitemap_menus'] = $ids_menu;
}
if (!empty($this->settings_sitemap['wpms_sitemap_menus'])) {
if (!empty($terms)) {
echo '<div id="menu_source_menus">';
foreach ($terms as $term) {
if (!in_array('sitemap_menus_' . $term->term_id, $check_menu)) {
$check_menu[] = 'sitemap_menus_' . $term->term_id;
echo '<div id="' . esc_attr('sitemap_menus_' . $term->term_id) . '" class="wpms_sitemap_menus">';
$viewmenu = $this->viewMenusFrontend($term, $ids_menu);
// phpcs:ignore WordPress.Security.EscapeOutput -- Content escaped in the method viewMenusFrontend
echo $viewmenu;
echo '</div>';
echo '<div class="' . esc_attr('holder holder_sitemaps_menus_' . $term->term_id) . '"></div>';
}
}
echo '</div>';
}
}
echo '</div>';
} elseif ($theme === 'accordions') {
wp_enqueue_style(
'wpms_materialize_style',
plugins_url('assets/css/materialize/materialize_frontend_accordions_theme.css', dirname(__FILE__)),
array(),
WPMSEO_VERSION
);
echo '<div id="wpms_sitemap" class="theme_accordions">';
echo '<ul class="collapsible wpms_collapsible" data-collapsible="accordion">';
$arrays = array();
if (!empty($this->settings_sitemap['wpms_sitemap_menus'])) {
$arrays['wpms_display_order_menus']
= WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/theme/accordions/source_menu.php';
}
if (!empty($this->settings_sitemap['wpms_sitemap_posts'])) {
$arrays['wpms_display_order_posts']
= WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/theme/accordions/source_posts.php';
}
if (!empty($this->settings_sitemap['wpms_sitemap_pages'])) {
$arrays['wpms_display_order_pages']
= WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/theme/accordions/source_pages.php';
}
if (!empty($this->settings_sitemap['wpms_sitemap_customUrl'])) {
$arrays['wpms_display_order_urls']
= WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/theme/accordions/source_urlcustom.php';
}
for ($i = 1; $i <= 4; $i ++) {
foreach ($arrays as $key => $item) {
if ((int) $this->settings_sitemap[$key] === (int) $i) {
require_once($item);
}
}
}
echo '</ul>';
echo '</div>';
}
return $html;
}
Code file location:
wp-meta-seo/wp-meta-seo/inc/class.metaseo-sitemap.php
WP Meta SEO [wpms_breadcrumb] Shortcode
The WP Meta SEO plugin shortcode, ‘wpms_breadcrumb’, is used to generate breadcrumb navigation for your WordPress site. This shortcode creates an HTML div with breadcrumb links. If the ‘reverse’ parameter is set to 1, the breadcrumb links will be displayed in reverse order.
Shortcode: [wpms_breadcrumb]
Parameters
Here is a list of all possible wpms_breadcrumb shortcode parameters and attributes:
reverse
– controls the order of breadcrumb items
Examples and Usage
Basic example – A simple implementation of the wpms_breadcrumb shortcode which will display the breadcrumb navigation in default order.
[wpms_breadcrumb /]
Advanced example – In this example, we will use the ‘reverse’ parameter of the wpms_breadcrumb shortcode. This parameter allows us to display the breadcrumb navigation in reverse order. To do this, we set the ‘reverse’ parameter to 1.
[wpms_breadcrumb reverse=1 /]
Note that the ‘reverse’ parameter only accepts integer values, where 1 means true (display the breadcrumb in reverse order) and 0 means false (display the breadcrumb in default order).
By using these shortcodes, you can easily customize the display of your breadcrumb navigation according to your site’s needs.
PHP Function Code
In case you have difficulties debugging what causing issues with [wpms_breadcrumb]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('wpms_breadcrumb', 'wpmsBreadcrumbShortcode');
Shortcode PHP function:
function wpmsBreadcrumbShortcode($params)
{
$html = '<div class="breadcrumbs" typeof="BreadcrumbList" vocab="https://schema.org/">';
if (isset($params['reverse']) && (int)$params['reverse'] === 1) {
$html .= wpmsBreadcrumb(true, true);
} else {
$html .= wpmsBreadcrumb(true, false);
}
$html .= '</div>';
return $html;
}
Code file location:
wp-meta-seo/wp-meta-seo/wp-meta-seo.php
Conclusion
Now that you’ve learned how to embed the WP Meta SEO 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.
Leave a Reply