Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8228597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:30:37+00:00 2026-06-07T16:30:37+00:00

I’m creating a Google Site Search custom search engine and I’m trying to display

  • 0

I’m creating a Google Site Search custom search engine and I’m trying to display certain metadata in the search results, using conditional markup to prevent certain things being shown. The metadata is stored on my pages using PageMaps, like this:

<!--
    Google Search PageMap
    <PageMap>
        <DataObject type="document">
            <Attribute name="type">project</Attribute>
            <Attribute name="title">Page title</Attribute>
            <Attribute name="topic">Page topic</Attribute>

            <Attribute name="topic_url">http://url.com/knowledge-hubs/resilient-catchments/river-restoration-partnerships/</Attribute>
            <Attribute name="knowledge_hub">Page knowledge hub</Attribute>
            <Attribute name="knowledge_hub_url">http://url.com/knowledge-hubs/resilient-catchments/</Attribute>
            <Attribute name="sniffer_code">ABC123</Attribute>
            <Attribute name="project_status">Active</Attribute>
            <Attribute name="project_start">1 August 2010</Attribute>
            <Attribute name="project_end">1 July 2012</Attribute>
        </DataObject>

        <DataObject type="thumbnail">
            <Attribute name="src">http://url.com/img.jpg</Attribute>
            <Attribute name="width">100</Attribute>
            <Attribute name="height">60</Attribute>
        </DataObject>
    </PageMap>
-->

Some pages generate all of this info, others just include a few things (e.g. title and type).

I want to be able to display whatever information is included here, depending on the page. This relies on conditional data-if attributes in the webResult template.

This is what I’ve got so far:

<article id="sniffer_webResult">
            <div class="gs-title">
                <a data-attr="{href:unescapedUrl,target:target}" class="gs-title">
                    <!--<span data-if="typeof richSnippet != 'undefined'" data-body="richSnippet.document.title"></span>-->
                    <span data-body="html(title)"></span>
                </a>
            </div>

            <div data-if="Vars.richSnippet" data-attr="0" data-body="render('thumbnail',richSnippet,{url:unescapedUrl,target:target})"></div>
            <div class="gs-snippet" data-body="html(content)"></div>
            <div data-if="typeof richSnippet != 'undefined'" class="meta">
                <!--<article data-if="richSnippet.document.type == 'project'">-->
                    <!--<div data-if="richSnippet.document.snifferCode != 'undefined'"><strong>Sniffer code: </strong><span data-body="richSnippet.document.snifferCode" data-attr="0"></span></div>-->
                    <div data-if="richSnippet && richSnippet.document.snifferCode"><strong>Sniffer code: </strong><span data-body="richSnippet.document.snifferCode" data-attr="0"></span></div>
                    <div data-if="richSnippet.document.projectStatus != null"><strong>Status: </strong><span data-body="richSnippet.document.projectStatus" data-attr="0"></span></div>
                    <div data-if="richSnippet.document.topic != null" class="topic"><strong>Topic: </strong><a data-attr="{href:richSnippet.document.topicUrl}" data-body="richSnippet.document.topic" data-attr="0"></a></div>
                    <div data-if="richSnippet.document.knowledgeHub != null" class="hub"><strong>Knowledge hub: </strong><a data-attr="{href:richSnippet.document.knowledgeHubUrl}" data-body="richSnippet.document.knowledgeHub" data-attr="0"></a></div>
                <!--</article>-->
            </div>
        </article>

(You can see I’ve been mucking about commenting things out etc.)

I can’t seem to get the conditionals to work. Some attributes work great though, so I’m almost there. Pages like the Homepage, which doesn’t include most of the attributes, give this error in the results:

TypeError: Cannot read property ‘snifferCode’ of undefined:
richSnippet && richSnippet.document.snifferCode

I’ve gone through the Google’s documentation here but I’ve not found it to be particularly comprehensive.

Any thoughts much appreciated! 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T16:30:38+00:00Added an answer on June 7, 2026 at 4:30 pm

    Have decided to go down the XML route and parse the results serverside before displaying them. This gives a lot more control over how and when page metadata is displayed, and overall it’s much more powerful. And it’s not as scary as it first appeared!

    richSnippets are useful for basic displays but I didn’t feel I could confidently control their display, so that’s another reason to go for XML instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.