Setting custom titles for the featured pages


Note :This snippet works only with the Classical style option. The Classical style option can be enabled in Appearance > Customize > Advanced > Theme Style. More about the theme style option here


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)

 

Customzir-Pro or Featured Pages Unlimited user ? Use this code  (only the filter’s name is different)

 

 

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.


Related Snippets you may also like


30 thoughts on “Setting custom titles for the featured pages

  • Rob H.

    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.

    • Menaka Sankaralingam

      Hi Rob,
      There is amissing comma at the end of this line. Add it and it should work.

      94 => ‘The Evolution of Flat Design’

  • Eli Diachenko

    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

      • Rocco Aliberti

        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. 🙂

        • Eli

          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

          • Rocco Aliberti

            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.

  • Marie

    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.

    • Marie

      (( 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.

      • Rocco Aliberti

        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 😉

        • Marie

          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!

  • 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!

    • Helena

      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!!

      • Marie

        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!

        • Helena

          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!

          • Marie

            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!

            • Rocco Aliberti

              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.

    • Helena

      Thanks Mark!

      Thanks Nikeo! Still awesome Theme!!!!

      Sorry, forgot to mention my issue was solved!

      Cheers!

  • Mark Sund

    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

    • Nicolas Post author

      Hi Mark,
      Just replace the name of the filter as follow :

      Thanks for using our solutions,
      Nicolas.

  • Terrie

    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?

  • Rihhard

    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.

    • Nicolas Post author

      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!

Comments are closed.