The-seo-framework: Provide Option to Strip HTML <tags> From Titles

Created on 22 Feb 2018  路  10Comments  路  Source: sybrew/the-seo-framework

Follow up from #265 because the topic got out of hand.

@GuardianMajor wrote:

As requested per our discussion in issue #138 where you wanted a simple request to be considered as a new feature.

A quick review, the ability to strip html tags sitewide with an option with a per post override for those times when you want literal tags to appear in the title of the post's page, the title of the shared items while retaining the formatting for the site front-end.

Thank you.

Suggested option name:

  • Strip HTML from autogenerated titles? [?]

Suggested [?] tooltip content:

  • This will convert valid HTML, like <span>example title</span>, to example title in all autogenerated titles.

Disabled by default.

Note to self: Articles should read this option.

[Type] Enhancement

All 10 comments

202 needs to be resolved first.

Temporarily workaround

Here's a dirty workaround filter that likely won't cause any issues:

add_filter( 'the_seo_framework_pro_add_title', function( $title ) {
    return wp_strip_all_tags( $title );
}, 0 );

The workaround will no longer work from 3.1.0!!

With the upcoming commit (3e7cfe3404bf9632a7b67672dac318ec47f90f16), we can move this to 3.1.0

In commit 3e7cfe3404bf9632a7b67672dac318ec47f90f16 we've implement the single_post_title filter, brought with WordPress, which is used in the default WordPress title rendering functions.

By default, WordPress runs PHP's SPL strip_tags() function over it:
https://github.com/WordPress/WordPress/blob/4.9.7/wp-includes/default-filters.php#L110-L114

I will not remove this filter. It makes sure the titles are automatically compatible with anything thrown at it. In fact, this behavior was already present on terms before this update.

Now, we need to reverse this functionality, instead of applying it.

Note: We need to copy this behavior in the JS placeholder writing. Where it strip tags as we write them when this option is disabled.

@sybrew Thank you for the hard work my friend and glad to see it coming. Just to make sure I understand, since this will now rely on the default behavior which strips the tags already, this means that this feature now behave by default as it does in the WP core, correct? Which you are right, would indeed make it unnecessary to have this additional setting. However, if someone still wanted to include tags in their title for say articles that are regarding coding, they can just escape them right?

Exactly, to all remarks 馃槃

鉂わ笍 Beautiful, you are awesome as always my friend, thank you.

I wanted to say thank you and kudos on the latest release, it looks wonderful and works excellent as always my friend, well done.

I did just want to say something about a little feature issue but I will open a ticket for that to keep it organized. Just wanted to confirm this feature is working as expected and thank you.

For the sake of future questions, just wanted to confirm that if you DO want the literal tags showing up, meaning say an article called: "How to use the \< as \< and > as \> and you will achieve this, correct and nothing is stripped?

Backslashes are used to handle functional characters as-is in code, they shouldn't be used to "hack" the system, and thus we remove them from the real output when deemed unnecessary.

With this, backslashes are unpredictable, too; we'll have to intricately perform checks on where whom has introduced what.

In any case, you'll have to write the HTML entities if you want to display the "exemplified" tags, with the escaping enabled, instead:

"&amp;"  = "&" (ampersand)
"&gt;"  = ">" (greater than)
"&lt;"  = "<" (less than)
"&#92;" = "\" (or bsol, backward solidus)

Pro tip: use &amp; to escape entities, so to show examples:

"&amp;gt;" => "&gt;"

Example: &gt;

You are absolutely right my friend, I have no idea why I said such a dumb thing, especially that I don't do it like that and exactly as you noted. I am embarrassed by a momentary thought lapse and have no idea what was running in my head when I said that, I should have known better. Please accept my apologies and know that I thank you for kindly replying to such a completely dumb remark, I can't even justify it, don't know what would motivate me to say something so stupid as it is not how I do it anyway. 鈽猴笍

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ratzrattillo picture ratzrattillo  路  3Comments

sybrew picture sybrew  路  6Comments

paaljoachim picture paaljoachim  路  5Comments

Hube2 picture Hube2  路  3Comments

LeBaux picture LeBaux  路  6Comments