There are cases when you need to set a custom titles for the featured pages displayed on front page.
By default, Customizr uses the titles that you have defined for your pages. You can easily change this with the following snippet.
1) Grab the page’s id for which you need to set this custom title (how to get a page’s id?)
2) Assign a custom title by page id in the $custom_title array below (I have set examples but you’ll need to change the id and custom titles values)
add_filter('tc_fp_title' , 'my_custom_fp_titles', 10 ,3); function my_custom_fp_titles( $original_title , $fp_id = null , $page_id = null ) { //assigns a custom title by page id $custom_title = array( //page id => 'Custom title' 2 => 'My custom title', 9 => 'Title Example for page id #9' ); //if no custom title is defined for the current page id, return original if ( ! isset($custom_title[$page_id]) ) return $original_title; return $custom_title[$page_id]; }
Customzir-Pro or Featured Pages Unlimited user ? Use this code (only the filter’s name is different)
add_filter('fpc_title' , 'my_custom_fp_titles', 10 ,3); function my_custom_fp_titles( $original_title , $fp_id = null , $page_id = null ) { //assigns a custom title by page id $custom_title = array( //page id => 'Custom title' 2 => 'My custom title', 9 => 'Title Example for page id #9' ); //if no custom title is defined for the current page id, return original if ( ! isset($custom_title[$page_id]) ) return $original_title; return $custom_title[$page_id]; }
Where to paste this code? => in your functions.php file. I strongly recommend to create a child theme. Download a start-up child theme here.
Everything you need to know about child theme with Customizr here.
30 thoughts on “Setting custom titles for the featured pages”
Thanks for the code here, but unfortunately it doesn’t work for me. When I add this to the bottom of my functions.php file (the copy of it in my customizr-child theme), the site stops working. Here’s the code I’m trying to use:
add_filter(‘tc_fp_title’ , ‘my_custom_fp_titles’, 10 ,3);
function my_custom_fp_titles( $original_title , $fp_id = null , $page_id = null ) {
//assigns a custom title by page id
$custom_title = array(
//page id => ‘Custom title’
92 => ‘What Makes a Good Logo?’,
94 => ‘The Evolution of Flat Design’
96 => ‘Design in Virtual Reality’
);
//if no custom title is defined for the current page id, return original
if ( ! isset($custom_title[$page_id]) )
return $original_title;
return $custom_title[$page_id];
}
The site is http://department203.com
I’m using Cpanel to edit the file. One thing I guess it might be is it asks which coding to use for the page, and I select the default (UTF-8). That’s the only thing I can think of that could be wrong. I’m using the standard (free) Customizr. Thanks.
Hi Rob,
There is amissing comma at the end of this line. Add it and it should work.
94 => ‘The Evolution of Flat Design’
Hey Rocco,
For some reason I am not able to get it to change. I tried both codes and stil does not work.
What am I doing wrong? Haha
Best,
Eli
http://www.cejsinc.com
Hello Eli,
I see you have the standard featured pages (shipped in Customizr free) so, first of all you should use the filter:
`tc_fp_title` and not `’fpc_title’` (first snippet)
then :
Commercial Janitorial Services page’s id (the first featured page) is 499 and not 24
Professional Office Cleaning pages’s id (the second) is 24 and not 499
If you still have problems after these changes, please share the whole content of your child-theme functions.php through pastebin.com (for a matter of legibility), we’ll try to see if there’s some unrelated issue which is preventing this code from working fine. 🙂
Hey Rocco,
Thanks for getting back to me! Unfortunately that did not work.
I thought I put the code to convert it to a pro theme, but maybe I did something wrong. I’ll look into more later.
It’s also not a child theme, but I changed the name of the theme so it does not get updated.
Here is the link for the functions.php file: http://pastebin.com/pw8m1fEv
Thanks for your help Rocco! Really appreciate it! 🙂
Best,
Eli
Hello Eli,
well, there’s no code to convert your theme in a pro theme, what do you mean?
Anyway the reason why that code isn’t working for you is that you put in in your style.css (there you can place just CSS snippets), which is the wrong place. You should put it at the very end of your functions.php
Hope this helps.
(reply to http://presscustomizr.com/snippet/setting-custom-titles-featured-pages/comment-page-1/#comment-326706)
Thanks Marie,
you’re welcome 😀
Hi Rocco. Thank you so much for coming to my rescue. Here are the details of my site and what I’m doing.
Site: http://www.ellaletraduce.co
Theme: Customizr Pro
Using child theme: yes
I go to my functions.php file on my child theme, click on code edit and do the following (I don’t have any other snippets in my php file):
Since it’s the only piece of code I use to close.
Thanks for the help.
(( edit )) The code in my previous comment looks incorrect, however I pasted it as it is at the top of this entry.
And since it’s my only piece of code on my php file I started with
Thank you once again for the help.
Hello Marie,
are you using the first or the second snippet?
As Customzir-Pro user you should use the second one, since FPU is embedded in Customizr-Pro.
Also, since you’re a premium user, if you have further problems, please, open a new topic in the Pro support forum 😉
You have no idea how silly I feel right now. Ugh. I am terribly sorry for putting you through all that.
Thank you. I was using the wrong code *smh*.
It works perfectly now. Now on to my next challenge: trying to set a URL that is not exactly a page. I installed a second wordpress within my hosting to build a microsite with my bio, and I’d like one of the featured pages to direct people to that URL.
Do you think that’s possible? If it is then I’ll definitely open a topic in the forum. Thank you Rocco. And sorry!
🙂 Don’t worry Marie, it happens 😉
You’re welcome.
You can direct people on an different url, you can try this snippet:
http://presscustomizr.com/snippet/setting-custom-links-featured-pages-customizr/
There’s also a trick to open the link in a new window/tab.
For example making this:
` 2 => ‘http://www.my-custom-url-one.com’,`
become this:
` 2 => ‘http://www.my-custom-url-one.com” target=”_blank’,`
Hope this helps 😉
you’re so kind. I will use it when the time comes of setting up that microsite.
Muchas gracias por la ayuda 😉
Marie
Hello and thanks for this awesome theme!
I’m using Customizr Pro and I tried using this snippet but the featured pages didn’t modify its names. It’s because it’s a newer version, right, and this works with 3.1.x?
Also, in case there is a way for this to work, I’m interested in what Helena asked. Using it with Polylang. THANK YOU!
Hi Maria,
I have used Mark’s code:
Each translated page has its own ID
‘add_filter(‘tc_fp_title’ , ‘my_custom_fp_titles’, 10 ,3);
function my_custom_fp_titles( $original_title , $fp_id = null , $page_id = null ) {
//assigns a custom title by page id
$custom_title = array(
//page id => ‘Custom title’
1507 => ‘my title 1st language’,
1673 => ‘my title 2nd language’,
1675 => ‘my title 3rd language’,
);
//if no custom title is defined for the current page id, return original
if ( ! isset($custom_title[$page_id]) )
return $original_title;
return $custom_title[$page_id];
}’
i hope it helps!!
Thank you Helena.
I have one question: did you see the changes automatically after you put the snippet in the PHP page? or it took some minutes?
Because I tried to change the featured pages and it didn’t work 🙁
I will try again. Thank you!
Hi @Maria,
It comes instantly for me.
Did you get the ids for your pages:
1507, 1673 and 1675 are the ids for my pages by ny website. You need to put your own id page nr there.
Hope you get it working!
I am just beginning to set up the website and haven’t installed Polylang yet. Still, the snippet is not working on my version of Customizr.
Thank you anyways for your help!
Hello Maria,
just tested it and this snippet works perfectly here.
Though I don’t get the reference to polylang. Polylang itself will not translate the featured page title, which is by default the selected page title. Polylang will, then, use the page title for the current language, but it will be ‘overridden’ by this snippet.
Hi,
How is the best way to use this code with Polylang?
Thanks!!!!
Thanks Mark!
Thanks Nikeo! Still awesome Theme!!!!
Sorry, forgot to mention my issue was solved!
Cheers!
Perfect – thanks – Mark
Thanks for the great theme and snippets. We just upgraded Featured Pages Unlimited from 1.3 to 1.10 and now this snippet is not working. It might have stopped working (and we didn’t notice) when we upgraded WordPress to 3.9. Are there any known issues with this snippet for WP 3.9 and FPU 1.10 ? Using child theme of Customizr 3.1.11.
Thanks, Mark Sund, Developer-Director, Sund + Co
Hi Mark,
Just replace the name of the filter as follow :
Thanks for using our solutions,
Nicolas.
First of all, thanks for the great theme! This code snippet worked great for one featured page, but I’m a bit confused on how to add a custom title to more than one. Do I copy and paste one specific area of the code?
Hi Terrie,
Just assigns a custom title by page id like shown in the code and it should work.
Thank you…works perfectly!
Is it possible to use custom titles with qTranslate plugin?
Right now if I enter my custom title with qTranslate tags ´[en] English title [et] Estonian tile´ my page shows both titles together.
Other buttons and slider is working using this method.
Hi Rihhard, this should work if you wrap your titles in the WordPress translation / internationalisation functions (more about that here https://codex.wordpress.org/I18n_for_WordPress_Developers)
For example, instead of :
write
Hope this helps!