WordPress Missing Page Title Javascript Fix

WordPress Missing Page Title PHP-Template $post Javascript Fix

The Problem

There are few things more annoying than a WordPress missing page title.

WordPress is an open-source platform.

Meaning developers and contributors from around the globe can submit tools, plugins and features to their heart’s content.

Although WordPress has a strong list of requirements a developer or contributor has to comply with, it is near impossible for every theme, plugin and the millions of combinations of different services and features any one website could be using to be tested and made sure everything is 100% compatible.

Sometimes life throws you a curveball you are not expecting. Such as a WordPress missing page title.

In this video… I demonstrate how I experience one such curveball.
Technically… nothing was broken, needed fixing, or caused an error.

But that didn’t mean everything was running as it should be.

The combination of multiple supplier plugins and third party themes already installed in several sites I’ve worked on recently simply didn’t sync 100% with the events plugin that I wanted to use.

All tools are fabulous and operate error-free.

It’s just for some bizarre reason, the Events plugin content template was being called and initiated before the page title variable had a chance to be populated.

The result, once the events pages had loaded into the user’s browser, was void of any Page Titles! It looked messy, amateur and needed a solution!

Read this article if you have a WordPress Missing Page Title and need a Javascript Fix! #WordPress #Javascript #PageTitle #Solutions Click To Tweet

Investigating the Solution

Like with anything in the world of development, when there is a problem you need to logically explore and work through the process to find where the challenges lie. It’s often a process of elimination to find the issue. As soon as you fix the first thing, another presents itself! So, a combination of many little things combines to create the challenge. In this video, there were 2 key issues to resolve.

Firstly, was the page able to work using a different template? After some tweaking and testing, we found that the title bar showed (less the title). Thus partially resolving the challenge.

The second was then to find a solution on how to initiate the variable that holds the page title BEFORE the events template was called into existence, thus the data existing to display a page title.
This was a bit more tricky and involved a little Javascript code and tweaking of the templates that managed the page.

The Solution

To duplicate a copy of the template that was successfully showing the page title bar.

Then inject into this template Javascript code, BEFORE the events template populated the page, so that the title existed and could be displayed.

Javascript code missing page title fix

18: grab a copy of the current global $post in use that is not showing the page in the browser

20: get a copy of the current object, and store a local copy of it in a variable we can run a test on.

22: check and see if the current object, contained the name tribe_events and handle the outcome it is was true/successful or false/not the correct object.

23: if we had the correct object, create a page title name and inject it into the global $post that the bowser uses to build then display the page.

25 & 26: send the current object to the post and display it as if nothing had occurred (still wrong, but at least the page loads).

Testing

Check to see how things look in the browser – job done!

Conclusion

If you are confident in following the approaches laid out in this video, then should you experience a similar challenge. You could resolve it cost-free.

Else…. remember.
McCall Media Studios is able to provide ad-hoc assistance with these curve-ball scenarios on a pay as you go basis.

Need more WordPress help? Check out our blog on WordPress Spam Prevention here

Solution Credit

We like to support our fellow industry experts and this solution was devised by Vicky of https://codeaddict.io

Share Article: