Okay, so I’m going it alone in some places and exploring how to logically deal with head items.
Some blueprints have the summary field which is a short intro, but nearly every blueprint has the text field. I’m also trying to strip out any quote marks in text.
I know this doesn’t use any ternary logic, but what would a better way to write this look like?
(I actually want to use the same logic to determine the SEO image: Use the site logo if it’s the homepage, otherwise use any uploaded page image instead.)
I think this is a great opportunity for me to learn how to do things the correct way in PHP from here on out. Thanks for your time, in advance!
If you don’t want to use one of the plugins, I’d create page methods that contain the logic, so that you don’t have to deal with all the logic in the header or metatag snippets. e.g. a $page->seoDescription() method, etc. then you metatag snippet will be reduced to
I understand the usual requirement of moving functions out of templates into methods and controllers, I think, but in this case, I want all of the logic in the header.php snippet for easy management. Using controllers and methods and routes are all still a little in upper (unreachable) headspace for me yet.
I did take my above code and make it work properly, though:
Finding the ucfirst tool was helpful, and it took a bit to realize that it had to be first with the code inside a parens instead of after a long chain of ->thing() instead.
My logic is still poorly written, though it does feel like an improvement. If I progress further I will likely realize that using those methods and routes are smarter, or it will click and I’ll start realize the power of the work others have already done with plugins and tutorials. Either way, I’m getting there.