Note that there are some explanatory texts on larger screens.

plurals
  1. POwordpress: actions, filters & hooks
    text
    copied!<p>I'm quite new to this (understanding the WP Guts), and I wanted to understand the Hooks and Filters better, I can't get it right from Codex.</p> <p>I did a simple test, </p> <p>the idea is to override the get_title() method in order to erase the "Protected: " sentence from the title if the page is protected, there is a protected_title_format filter, and I thought using it ...</p> <p>that line in <em>post-template.php</em> specifies:</p> <pre><code>$protected_title_format = apply_filters('protected_title_format', __('Protected: %s')); </code></pre> <p>for what I could get from CODEX, I need to remove that filter and add my own, like</p> <pre><code>remove_action('protected_title_format'); apply_filters('protected_title_format', __('MY OWN PAGE Protected: %s')); </code></pre> <p>using, off course something like</p> <pre><code>// Removing action function remove_title_action() { remove_action('protected_title_format','get_the_title',3); } add_action('init','remove_title_action'); // Adding custom function add_action('protected_title_format','fancy_title', 3, 4); function fancy_title($id = 0) { $post = &amp;get_post($id); $title = $post-&gt;post_title; echo "I'm the king of the world!... &gt;" . $title . "&lt; &amp; &gt;" . $post . "&lt;"; if ( !is_admin() ) { if ( !empty($post-&gt;post_password) ) { $protected_title_format = apply_filters('protected_title_format', __('MY OWN PAGE Protected: %s')); $title = sprintf($protected_title_format, $title); } } return apply_filters( 'the_title', $title, $post-&gt;ID ); } </code></pre> <p>I can get the echo to output, but I dont get the $id (and for that, no $title or $post), this method is a copy of get_title() stripping out everything but the protected part string.</p> <p>Can anyone care to explain me <strong>how this works</strong>? Thank you</p> <hr> <p><strong>P.S.</strong> I want to learn, this is the idea of this question, not someone to tell me "Hey, just go to post-template.php and change it", because then I would ask "How about when I update WP...?" !</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload