Tagged: breadcrumb, H1, title
I am using the following code that I found on the net, in functions.php of my enfold-child theme..
add_filter('the_title','some_callback');
function some_callback($data){
global $post;
if(!is_page()) return $data;
return 'HELLO ' . $post->ID . ' - ' . $data;
}
This does change the title, but it also changes the titles in the breadcrumbs too. Is there a way for this to only affect the title in the h1 tag on the page? Or another method/plugin?
Ultimately all I need to do is change the h1 titles on a handful of pages, I don’t mind hard coding them in functions.php
Hi elp!
Use is_page inside that function to filter certain pages only (ID):
<?php
add_filter('the_title','some_callback');
function some_callback($data){
global $post;
if(!is_page()){
return $data;
}elseif(is_page(42){
return 'HELLO ' . $post->ID . ' - ' . $data;
}
}
You can also pass an array to is_page(), ex: is_page(array(23, 32));
http://codex.wordpress.org/Function_Reference/is_page
Cheers!
Josue
Just to follow up and share what actually worked for me.. I used a long & friendly title for the page, then I overrode the text for the breadcrumbs.
add_filter('the_title', 'enfold_child_the_title');
function enfold_child_the_title($data){
global $post;
if(is_in_function('avia_breadcrumbs')){
// NOTE: check if $data has already been changed to the menu text
if (!($data === $post->post_title)) return $data;
switch ($post->post_name) {
case 'myslug': return 'My Short Title';
// etc..
}
}
return $data;
}
function is_in_function($functionName)
{
foreach (debug_backtrace() as $k => $v) {
if ($k < 2) continue; // ignore self & caller
if ($v['function'] === $functionName) return true;
}
return false;
}