HOW TO: Extract and show heading text in h1, h2, h3, etc.

Discussion about site promotion and issues affecting search engine listings and rankings.
Post Reply
User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3231
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

HOW TO: Extract and show heading text in h1, h2, h3, etc.

Post by Albert Wiersch » Tue Oct 03, 2017 3:53 pm

If you've ever wondered what your website's heading text is then this small user function can help.

The function causes CSS HTML Validator to generate a message that extracts and shows the heading text every time the "h1" heading tag is used.

You can also add functions for the other HTML heading elements as well (h2, h3, h4, etc). For example, use a function named onEndTag_h2() to generate a message every time the "h2" heading element is used.

Just save the function in a text file with a txt of cfg file extension and specify the filename in the Config File options page in the Validator Engine Options (Ctrl+F4). Be sure to reload the configuration so that the script takes effect.

Code: Select all

function onEndTag_h1() {
 Message(1, MSG_MESSAGE, 'h1 heading text: '+getValueString(33), getLocation(3,0));
}
You can also add functions for the other HTML heading elements as well (h2, h3, h4, etc). For example, add a function named onEndTag_h2() to also generate a message every time the "h2" heading element is used.

Code: Select all

function onEndTag_h1() {
 Message(1, MSG_MESSAGE, 'h1 heading text: '+getValueString(33), getLocation(3,0)); 
}

function onEndTag_h2() {
 Message(1, MSG_MESSAGE, 'h2 heading text: '+getValueString(33), getLocation(3,0));
}
Use the MessageEx() function for more advanced messages, like messages with a message ID and message category:

Code: Select all

function onEndTag_h1() {
 MessageEx(5, 2017100300, MSG_MESSAGE, 'H1 Heading Text', 'h1 heading text: '+getValueString(33), getLocation(3,0));
}
Note: When a message category is used, the message is typically displayed in the Grouped tab in the Results Window.

For more about what you can do with scripting in CSS HTML Validator, visit:
https://www.htmlvalidator.com/v170/docs ... nguage.htm
Image
Albert Wiersch

Post Reply