We often get the question: how do I prevent the items in the menu from showing-up in the search results? Here are some answers.
As of version 2.1 of O-SE, there is really no way to exclude portions of the content of a page.
Generally, the text from the menu and breadcrumbs is showing-up when you enter a search word that matches a menu title.
O-SE indexes the content of the whole page as shown in a browser, thus it does not know that the text is coming from a menu.
There is a workaround suggested by one of our clients, that we thought was brilliant.
He changed the names of his menus so as to contain an html representation of the character, instead of the character itself.
For example: if you have a menu item called "menu item", you could edit its name to be: "menu item"
where "m" is the html encoded representation of "m".
The result of this change will be that to the regular user, the menu will still be represented normally, but to Open-SearchEngine, it will not match a search on "menu item", thus it will not be rendered in the search results.
there is a list of symbols here:
http://www.avenue-it.com/html/asciialphabet.html
Building on this first suggestion, Keith Flores graciously offered an automated way of doing this, by adding a little javascript to the DNN skin:
<|code|>//************************************************************//
// AHB hack to make Open-SearchEngine index pages properly by
// HTMLencoding menu text on each page automatically, which
// keeps the Admin user from having to do it manually each time
// a "Page Name" is added (on a new page) or changed (on an
// existing page).
//************************************************************//
if (document.getElementById("dnn_ctr_ManageTabs_txtTabName")) {
// EXISTING pages which will already have a Page Name; idea is to change
// ASCII character to a regular character while Page Settings are being viewed
// If a page currently has the old way of first character not being ASCII format,
// nothing will happen to it until page is saved.
var pageName = document.getElementById("dnn_ctr_ManageTabs_txtTabName").value;
if (pageName.charAt(0) == "\&") { // Is first character of Page Name an ampersand
// Modify Page Name at page load from ASCII code to character
var colonIndex = pageName.indexOf(";");
var cutAscii = pageName.substring(0,colonIndex+1); // Extract ASCII code
var cutPageName = pageName.substring(colonIndex+1); // Extract page name without ASCII code
var cutNum = pageName.substring(2,colonIndex); // Extract ASCII number
var firstChar = String.fromCharCode(cutNum); // Convert ASCII number to character
document.getElementById("dnn_ctr_ManageTabs_txtTabName").value = firstChar + cutPageName;
}
// Add onclick when page is saved to convert first character of Page Name into
// ASCII format
var updateButton = document.getElementById("dnn_ctr_ManageTabs_cmdUpdate");
updateButton.onclick = function() {
// For NEW or EXISTING pages, on page save, change first character of
// Page Name to ASCII code which makes Open-Search Engine ignore the page's
// title in the HTML menus
var pageName = document.getElementById("dnn_ctr_ManageTabs_txtTabName").value;
var strCharEnc = pageName.charCodeAt(0); // ASCII encode first character in Page Name
document.getElementById('dnn_ctr_ManageTabs_txtTabName').value = "\&#" + strCharEnc + ";" + pageName.substr(1);
}
}
<|/code|>
Thanks to Keith Flores for providing the code.