CMS Development

jmarcello
Participant

Blog Search Results / Description length and text

Hi

 

We'd like to truncate the description with a very specific character count. The name=length value=short or long parameters are to restrictive and the chosen text is poor as it is based on the search results order hierarchy (see below).

 

Length

How can we select a very specific character counter to return in the description? Also it would need to always truncate at a complete word.

Text

 

As it stands the selected text for the search result is not always the from the blog content.

For instance, if the search result is returned because it was a Meta description (see #2 below), the returned text is the meta description and then the blog content.

 

We need to returned desciption to alway be the blog content. Essentially this will be the first sentence or so of the blog post body.


This relates to the search results order hierarchy...

 

  1. HTML title
  2. Meta description
  3. H1 HTML elements
  4. H2 HTML elements
  5. H3 HTML elements
  6. Other HTML elements

Any help is greatly appreciated.

0 Upvotes
3 Replies 3
Kevin-C
Recognized Expert | Partner
Recognized Expert | Partner

Blog Search Results / Description length and text

Hey @jmarcello

 

2 very different issues here.

 

Unfortunately I can't speak to the search functiuonality. Maybe someone from hubspot can weigh in.

 

But for you truncation I'd double chek the hubspot docs, I know a few features do include truncations. If its not avaliable it might be worth looking into a jQuery script or plugin. Here are a few.

Kevin Cornett - Sr. Solutions Architect @ BridgeRev
0 Upvotes
jmarcello
Participant

Blog Search Results / Description length and text

I have attempted three different jQuery plugins and cannot seem to get them to work with the search results Description.

 

The one I want to use looks very simple called "Succinct", however no matter what I do it does not seem to execute the truncation.

 

Is there some one who would be willing to help me implement it via something like Google Hangouts or Zoom?

 

I have already tried about 25 different permutation with zero success.

Any help is greatly appreciated.

0 Upvotes
Kevin-C
Recognized Expert | Partner
Recognized Expert | Partner

Blog Search Results / Description length and text

Good morning @jmarcello

 

Below I've created a jQuery function that'll truncate the text for you. Its been annotated for ease of use. As a best practice I would remove the comments when publishing, but its not necessary.

 

$(document).ready(function(){
  var target = $('.para'), //Define the element you with to target here
      truncLength = 15;//Set the length you would like here
 
  target.each(function() {//Loop through all target elements
    console.log(this);//Console log to ensure youre targeting correctly
    var string = this.innerHTML;//Get the current targets text
    if (string.length <= truncLength) {//If the length of the text string is less than or equal to the truncLenght, skip the truncation step
      //Do nothing
    } else {
      string = string.substring(0, truncLength) + "…";//Truncate the targets text starting at position 0
      console.log(string);// Console log the new value
      this.innerHTML = string;//Update the DOM with the new text string
    }
  });
});

Let me know if this helps!

Kevin Cornett - Sr. Solutions Architect @ BridgeRev
0 Upvotes