I am using the accepted answer shown here: Apply the_title() filter in post & page title, but not in menu title

For some reason, the code is getting through this if statement twice:

if ( ! is_admin() && $post instanceof WP_Post && ( $post->post_type == 'page' ) && in_the_loop() && is_main_query() ) {

I am already using the pre_wp_nav_menu and wp_nav_menu_items filters as shown on that answer.

What would be making this code run twice please? Or how would I debug to find out what is calling it and letting it through the if twice?

Sorry, I would ask as a follow-up on the posted question, but I evidently can't comment yet.

UPDATE: I used debug_traceback to determine what functions were calling this function twice. The answer: function the_title in post-template.php (line 43) and function the_title_attribute in post-template.php (line 89) (which is evidently used to sanitize the title)

Interestingly, when signed in on wordpress, only line 89 gets called and NOT line 43 so the add_filter 'the_title' function only gets called once if you are signed in.

So...Is it fine to leave add_filter 'the_title' as being called twice if you are not signed in...or why is it only called once if you ARE signed in?

  • is this the answer or is this the comment? Stack exchange isn't a discussion forum, an answer is a self contained solution to the question. If you want to add more information to your question, you should edit it or leave a comment instead
    – Tom J Nowell
    Mar 7 '21 at 18:50
  • Noted, thanks. I've updated the question.
    – l_r
    Mar 7 '21 at 19:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.