Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9065239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:27:07+00:00 2026-06-16T16:27:07+00:00

I’m using a translation plugin which creates a hook for the_title, the_content and other

  • 0

I’m using a translation plugin which creates a hook for the_title, the_content and other things.
All is working fine except one bit of code that does not display the title.
It uses this code:

$page_title = apply_filters('the_title',get_the_title());

If i try to use get_the_title() or the_title(), it breaks.

What does apply filters do, and how do i make it not skip the hook from the translation plugin?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T16:27:08+00:00Added an answer on June 16, 2026 at 4:27 pm

    the_title and the_content also exist in the WordPress core. They are utilized for many things. Why a line like that is useful is apparent if you know what hooks are.

    Filter hooks and Action hooks are essentially laundry lists. You can put functions on a hook, one after another so they form a queue, and when this hook is called on (by do_action and apply_filters respectively) WordPress will unqueue one function after another. As it does, it will execute them.

    add_action( 'test', 'func1' );
    add_action( 'test', 'func2' );
    do_action( 'test' ); // Executes func1 and then func2
    

    The difference between actions and filters is that while they can both accept values, only filters will return a modified value. Actions do something that is important in and of itself; filters take a value and return a modified version of it that can be used later on. For example, to capitalize every title that’s printed with the_title we can use the following piece of code:

    add_filter( 'the_title', function( $title ) {
        return strtoupper( $title );
    });
    

    Since we know that all functions hooked on the_title – the hook and not the function – will be executed only by apply_filters we expect to find it somewhere in function the_title. Actually that function is basically echo get_the_title and here’s how get_the_title looks:

    function get_the_title( $id = 0 ) {
            $post = &get_post($id);
    
            $title = isset($post->post_title) ? $post->post_title : '';
            $id = isset($post->ID) ? $post->ID : (int) $id;
    
            if ( !is_admin() ) {
                    if ( !empty($post->post_password) ) {
                            $protected_title_format = apply_filters('protected_title_format', __('Protected: %s'));
                            $title = sprintf($protected_title_format, $title);
                    } else if ( isset($post->post_status) && 'private' == $post->post_status ) {
                            $private_title_format = apply_filters('private_title_format', __('Private: %s'));
                            $title = sprintf($private_title_format, $title);
                    }
            }
            return apply_filters( 'the_title', $title, $id );
    }
    

    I’m posting the entire function because learning to look for hooks in the source code is of utmost importance for bourgeoning WordPress developers. The source code is littered with hooks, and so they can be used to modify many aspects of the built-in functions of WordPress. Now that you’ve located apply_filters( 'the_title', ... ) in the source code, you can appreciate its importance!

    the_title simply echoes the value given to it by get_the_title and you can modify or even replace the value that get_the_title returns by attaching a filter to the hook the_title!

    Now, I hope you don’t think all that I’ve written so far is gratuitous. In fact, now we can easily answer your main question which was “why does it not work?”

    First of all, you can never pass the_title to a function! It would be like writing somefunction( $var1, echo $var2, $var3 ). We cannot pass a value to a function by using echo, because echo sends its output to the browser.

    The better attempt is the one you posted

    $page_title = apply_filters('the_title',get_the_title());
    

    But as we’ve seen, get_the_title has applied the_title to its return value already. You’re simply applying all those functions a second time. It could result in strangeness if you have some custom filters attached to the_title or it could do nothing. So it either muddles the result or is gratuitous. Which is why you should simply do this:

    $page_title = get_the_title();
    

    Now, you also said

    All is working fine except one bit of code that does not display the
    title

    This is confusing, because we would not expect a variable assignment to output anything! To output the title, you could do this

    $page_title = get_the_title();
    echo $page_title;
    

    But as we’ve learned, this is really (look at the source code for the slight difference) the same as:

    the_title();
    

    So I wrote quite a lot just to come to the conclusion that you probably want to use the_title on its own. But I hope this can be a good resource on filter/action hooks as well.

    Any questions are welcome.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am using JSon response to parse title,date content and thumbnail images and place
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.