I wasn't crazy about the solution provided here since I use the same TERM for Ubuntu virtual terminals as other terminals (screen-256color). Thus, I took a quick look at what other environment variables could be useful for this purpose.
My conclusion was to use the XDG_VTNR (XDG virtual terminal number?) variable. Since Ubuntu uses VT#7 for the desktop environment, a simple check for whether this variable is greater than or equal to 7 does the trick.
I have bash function that builds my prompt anyway, so I just surrounded the title escape sequence addition with a check against the XDG_VTNR variable.
For example, note the bolded portion below:
# Use new test (i.e. [[ ]]) so as not to fail if XDG_VTNR does not exist
if [[ $XDG_VTNR -ge 7 ]]; then
# Add the window title escape sequence to the prompt
# Don't add the window title escape sequence to the prompt
Just wanted to add this note in case it can be useful for anyone else.