Please or Register to create posts and topics.

SEO for Breadcrumbs – Microdata

PreviousPage 2 of 2

Hello Thomas,

Ok, I look

Everything works perfectly!

Thank you for your feedback! As promised it will be included in the upcoming v1.4 release which should be available in the next two weeks (maybe earlier). 🙂

If you want to support the development of Asgaros Forum, you can leave a good review or donate. Thank you very much!

Hello,

I have fixed some problems with breadcrumbs (related with rich snippets) recently which will increase your SEO optimization, also current link has been removed from the breadcrumb for the SEO optimization (current links always hurt your optimization for search engines). If you are having problem with breadcrumbs (I know everyone don’t get this problem), you can replace codes below with current forum-breadcrumbs.php codes.

You can replace your forum-breadcrumbs.php with the codes below.

 

<?php

if (!defined('ABSPATH')) exit;

class AsgarosForumBreadCrumbs {
    public static $breadCrumbsLevel = 4;
    public static $breadCrumbsElements = 0;
    private static $breadCrumbsLinks = array();

    public static function addToBreadCrumbsList($link, $title, $position = false) {
        self::$breadCrumbsLinks[] = array(
            'link'      => $link,
            'title'     => $title,
            'position'  => $position
        );
    }

    public static function showBreadCrumbs() {
        global $asgarosforum;

        if ($asgarosforum->options['enable_breadcrumbs']) {
            if (self::$breadCrumbsLevel >= 4) {
                $elementLink = $asgarosforum->getLink('home');
                $elementTitle = __('Forum', 'asgaros-forum');
                self::addToBreadCrumbsList($elementLink, $elementTitle, 1);
            }

            // Define category prefix.
            $categoryPrefix = '';

            if (self::$breadCrumbsLevel >= 4 && $asgarosforum->current_category) {
                $category_name = $asgarosforum->get_category_name($asgarosforum->current_category);

                if ($category_name) {
                    $categoryPrefix = $category_name.': ';
                }
            }

            // Define forum breadcrumbs.
            if (self::$breadCrumbsLevel >= 3 && $asgarosforum->parent_forum && $asgarosforum->parent_forum > 0) {
                $elementLink = $asgarosforum->getLink('forum', $asgarosforum->parent_forum);
                $elementTitle = $categoryPrefix.esc_html(stripslashes($asgarosforum->parent_forum_name));
                self::addToBreadCrumbsList($elementLink, $elementTitle, 2);
                $categoryPrefix = '';
            }

            if (self::$breadCrumbsLevel >= 2 && $asgarosforum->current_forum) {
                $elementLink = $asgarosforum->getLink('forum', $asgarosforum->current_forum);
                $elementTitle = $categoryPrefix.esc_html(stripslashes($asgarosforum->current_forum_name));
                self::addToBreadCrumbsList($elementLink, $elementTitle, 2);
            }

            if (self::$breadCrumbsLevel >= 1 && $asgarosforum->current_topic) {
                $name = stripslashes($asgarosforum->current_topic_name);
                $elementTitle = esc_html($asgarosforum->cut_string($name));
                self::addToBreadCrumbsList($elementLink, $elementTitle, 3);
            }

            if ($asgarosforum->current_view === 'addpost') {
                $elementLink = $asgarosforum->getLink('current');
                $elementTitle = __('Post Reply', 'asgaros-forum');
                self::addToBreadCrumbsList($elementLink, $elementTitle);
            } else if ($asgarosforum->current_view === 'editpost') {
                $elementLink = $asgarosforum->getLink('current');
                $elementTitle = __('Edit Post', 'asgaros-forum');
                self::addToBreadCrumbsList($elementLink, $elementTitle);
            } else if ($asgarosforum->current_view === 'addtopic') {
                $elementLink = $asgarosforum->getLink('current');
                $elementTitle = __('New Topic', 'asgaros-forum');
                self::addToBreadCrumbsList($elementLink, $elementTitle);
            } else if ($asgarosforum->current_view === 'movetopic') {
                $elementLink = $asgarosforum->getLink('current');
                $elementTitle = __('Move Topic', 'asgaros-forum');
                self::addToBreadCrumbsList($elementLink, $elementTitle);
            } else if ($asgarosforum->current_view === 'search') {
                $elementLink = $asgarosforum->getLink('current');
                $elementTitle = __('Search', 'asgaros-forum');
                self::addToBreadCrumbsList($elementLink, $elementTitle);
            } else if ($asgarosforum->current_view === 'subscriptions') {
                $elementLink = $asgarosforum->getLink('current');
                $elementTitle = __('Subscriptions', 'asgaros-forum');
                self::addToBreadCrumbsList($elementLink, $elementTitle);
            } else if ($asgarosforum->current_view === 'profile') {
                $asgarosforum->profile->setBreadCrumbs();
            }

            // Render breadcrumbs links.
            echo '<div id="breadcrumbs-container">';
                echo '<div id="breadcrumbs" typeof="BreadcrumbList" vocab="https://schema.org/">';
                    echo '<span class="dashicons-before dashicons-admin-home"></span>';
                    foreach (self::$breadCrumbsLinks as $element) {
                        self::renderBreadCrumbsElement($element);
                    }
                echo '</div>';
                echo '<div class="clear"></div>';
            echo '</div>';
        }
    }

    public static function renderBreadCrumbsElement($element) {
        if (self::$breadCrumbsElements > 0) {
            echo '<span class="dashicons-before dashicons-arrow-right-alt2 separator"></span>';
        }
    
    if (self::$breadCrumbsElements <= 2){
        echo '<span property="itemListElement" typeof="ListItem">';
            echo '<a property="item" typeof="WebPage" href="'.$element['link'].'" title="'.$element['title'].'">';
            echo '<span property="name">'.$element['title'].'</span>';
            echo '</a>';
      }

    if (self::$breadCrumbsElements > 2){
        echo '<span property="itemListElement" typeof="ListItem">';
            echo '<property="item" title="'.$element['title'].'">';
            echo '<span property="name">'.$element['title'].'</span>';
      }
            if ($element['position']) {
                echo '<meta property="position" content="'.$element['position'].'">';
            }
        echo '</span>';

        self::$breadCrumbsElements++;
    }
}

Thanks to asgaros for providing this to us.

Didn’t use the webpage for current item because I believe it’s breaking the harmony of the breadcrumbs. 😀 Somehow I don’t recommend this at all. If you ask me why… I don’t know really:D heh. If you would like to use webpage for current item replace

echo '<property="item" title="'.$element['title'].'">';

with

echo '<property="item" typeof="WebPage" title="'.$element['title'].'">';

BTW: I am creating websites almost 16 years and I have never created a company for that but I believe I am good at SEO. An important note for those who are calling this plugin “not seo friendly”: When you have breadcrumbs, you don’t also need seo links much. Breadcrumbs will do the work. + If your forum doesn’t get any index (and if you worry about this), you should create a sitemap for the forum. That’s why you are not getting index (or your indexed content disappears from search results.)

Hello faramirtr,

thank you for your post!

current links always hurt your optimization for search engines

What is the reason for this? Is there any source which can explain it a little bit more in detail? The problem is, that the current-topic link always links to the first page. So basically when you are at the second page of a topic, the link to the beginning would not be there anymore with your code. The same holds when you edit a topic (….. -> My Topic -> Edit Post). In this case its not possible anymore to go back to the topic inside the breadcrumbs.

If you want to support the development of Asgaros Forum, you can leave a good review or donate. Thank you very much!
PreviousPage 2 of 2