Hello again!
The difference from here and there is that the one on my site is for educational purposes, and the one I posted here is a real-world execution.
If I add too many conditions (ifs and elses) on the educational front, users will have to question the implementation, which adds much to confusion if they’re not savvy with PHP or critical programming.
To explain the actionable difference:
The custom meta field doesn’t always have content in it. To run an expensive, although optimized function (do_shortcode()
) over an empty field is a waste of resources. So, we first assess if there’s content, and then run the function.
Let’s move on to your other questions…
How do I remove HTML symbols, like –
(–)
You can’t. This is a result of a low-entropy security feature. With that, I mean that there’s a net-loss of near zero from your input to the actual output. The symbols closely resemble the ones you’ve put in (they’re “beautified”), and it won’t affect SEO ranking.
It may cause the pixel counter to be off by a few pixels, which, on edge-cases, will cause the title or description to overflow regardless.
og:title and twitter:title tag support
Oops! My bad, I forgot to include those. I see you’ve already found them. Just to affirm, here you go:
// Enables shortcode parsing for the og:title output.
add_filter( 'the_seo_framework_ogtitle_output', function( $title ) {
return do_shortcode( $title );
} );
// Enables shortcode parsing for the twitter:title output.
add_filter( 'the_seo_framework_twittertitle_output', function( $title ) {
return do_shortcode( $title );
} );
When should I utilize the Twitter and Open Graph inputs?
Twitter and Facebook have different title-and description truncation standards to Google. You may want to account for those; but, more importantly, if you think you can cater to the interest of your Twitter and Facebook followers with different inputs, then they’re there for you.
For me, I often don’t even bother. But that’s because my target audience isn’t pronounced on either of those sites.
You made my shortcode “safer”, what did you do?
I made it safer by changing the name and (redundantly) escaping the output. current_date()
looks a lot like a standard PHP or WordPress function; may they ever add such a function internally, then your code won’t collide and crash.
So, I discarded the function name completely, and made it an anonymous lambda function:
some_call( function() { /* this is the lambda function, as it has no name */ } );
The same principle is followed for the shortcode; I added a prefix (title-
) to it; to prevent it from ever colliding with a WordPress, theme, or plugin update.
So, before you stretch me thin asking to improve your code: Go and play with them yourself, you may learn a thing or two ??
I hope this all helps! Have a beautiful day!
-
This reply was modified 5 years, 12 months ago by
Sybre Waaijer. Reason: formatting