我很新的这(理解WP胆量),我想了解的钩子和过滤器更好,我不能直接从食品得到它。
我做了一个简单的测试,
这个想法是覆盖get_title()方法,以清除“受保护的:”从标题句,如果该页面已被保护,有一个protected_title_format过滤器,我想用它...
在-的template.php后该行规定:
$protected_title_format = apply_filters('protected_title_format', __('Protected: %s'));
什么我可以从CODEX得到,我需要删除过滤器和添加自己的,像
remove_action('protected_title_format');
apply_filters('protected_title_format', __('MY OWN PAGE Protected: %s'));
使用,关闭过程类似
// 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 = &get_post($id);
$title = $post->post_title;
echo "I'm the king of the world!... >" . $title . "< & >" . $post . "<";
if ( !is_admin() ) {
if ( !empty($post->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->ID );
}
我能得到回音输出,但我不得到$ ID(并为没有$标题或$ POST),这种方法是()剥离出来的一切,但受保护的部分串get_title的副本。
任何人都可以照顾解释我是如何工作的 ? 谢谢
PS我想学习,这是这个问题的想法,不是有人告诉我:“嘿,只是去到的template.php后并改变它”,因为那样的话我就问:“怎么样,当我更新WP ... ?” !