Setting custom links for the featured pages in Customizr


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 links for the featured pages displayed on front page.

By default, Customizr links to the page you have choosen in the dropdown list (see the featured pages documentation)  . You can easily change this with the following snippet.

1) Grab the page’s id for which you need to set this custom link (how to get a page’s id in WordPress?)

2) Assign a custom link by page id in the $custom_link  array below (I have set examples but you’ll need to change the id and custom link values)

 

 

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


71 thoughts on “Setting custom links for the featured pages in Customizr

  • Amber

    Hey Nicolas,

    I’m not exactly familiar with coding, but I’m getting there. I’m trying to link the first feature page to a category page. This is pasted in the child. So 97 is the page I can link to in the options, and cat=4 is the category page I want it changed to. I’ve tried with the full link as well. Do you have a suggestion as to what I’m doing wrong?

    Site is http://www.nativeamericanmuseum.org/

    add_filter(‘tc_fp_link_url’ , ‘my_custom_fp_links’, 10,2);

    function my_custom_fp_links( $original_link , $fp_id ) {

    //assigns a custom link by page id
    $custom_link = array(
    //page id => ‘Custom link’
    97=> ‘http://www.nativeamericanmuseum.org/?cat=4’
    );

    foreach ($custom_link as $page_id => $link) {
    if ( get_permalink($page_id) == $original_link )
    return $link;
    }

    //if no custom title is defined for the current page id, return original
    return $original_link;
    }

  • Erin Coss

    I’m really struggling to make this code work on my site.

    My site is located here: http://new.connectionsvolunteercenter.org/wp/

    I’m trying to get the first featured page circle “Volunteer” to link to my subdomain here: http://volunteer.connectionsvolunteercenter.org/wp/

    I’ve tried and tried to no avail. I’ve pasted the following into the functions.php file.

    Any thoughts would greatly be appreciated! Thank you!

    • Nicolas Post author

      Hi Erin,
      This filter requires two parameters to work properly, therefore when you declare it you need to use the following syntax:

      Hope this helps !

    • Rocco Aliberti

      Hello Erin,
      in addition to what Nicolas said, since you use customizr-pro you should use, as written in the snippet:
      add_filter('fpc_link_url' , 'my_custom_fp_links', 10 ,2);
      and not
      add_filter('tc_fp_link_url' , 'my_custom_fp_links', 10 ,2);

      Hope this helps.

  • wiwe2210

    hi,

    i cant seem to figure out what parts of the code to edit so that i wil link to a categorie. does anyone have a more detaild instruction on how to edit this code.

  • Contact

    Yep this definitely doesn’t work for me now matter how I type it. Went through all the comments above. Not getting any errors, but nothing happens. Here’s my code:

  • Ruben Jesus

    Hello,

    i have put the code you describe in your text and changed to my category id, and i get the following error in my site:
    Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘my_custom_fp_links’ not found or invalid function name in /home/kanesbit/public_html/geekstuff/wp/wp-includes/plugin.php on line 213

    i havent change any code in other files.
    Thanks for your help.

    • Nicolas Post author

      Hi, the error message is saying that the function my_custom_fp_links has not been declared properly and you can’t use it as a callback for your WordPress action.
      Hope this helps 🙂

  • Susie Forrest

    I am a newbie, and just uploaded a child theme functions.php file in order to create a link from my home page to my YouTube channel.

    I received this error:

    Parse error: syntax error, unexpected ‘http’ (T_STRING), expecting ‘)’ in /home/content/p3nexnas05_data02/63/2125863/html/wp-content/themes/customizr-child/functions.php on line 11

    I cannot access my website!

    Thank you, for any assistance!

    http://www.forrestproperties.com

  • crosswire

    so i added the above code.
    the buttons on the front featured page don’t goto the urls i specified.

    1) Grab the page’s id for which you need to set this custom link (how to get a page’s id in WordPress?)
    am i suppose to use the ID of the page where i want to go when button is clicked?

    When i goto customize, am i supppose to see something in the dropdown or will the front page just update itself with the links on the buttons

    • Nicolas Post author

      Hi,
      1) this is the page id of the paged you display as featured page, not the target.
      2) you won’t see anything different in the customizer, the snippet changes things on the live site only

      Hope this helps, thanks

  • marilena

    Hello everyone.
    I would like to add custom urls to posts’ featured images of a specific category. I’ve done some research, I’ve added a custom field named ‘external_url’, but I don’t know where to put this code:

    Does it go to the theme functions.php or somewhere else? Can anyone help me please?

  • eric lugo

    Hi – I was reading this post as I was trying to modify the featured pages on the homepage of my customizr theme to display categories. I pasted the code into the functions.php file under editor and my page is now crashed. I keep receiving an error saying the following:

    Parse error: syntax error, unexpected ‘=’ in /home/content/p3pnexwpnas01_data01/11/2223211/html/wp-content/themes/customizr/functions.php on line 61

    I’m not unable to edit anything through my admin account and cannot view the website externally as well. Is there any guidance you can provide on how to fix this?

    Thanks,
    Eric

  • Kurt

    I added the code to make one of the featured links go to our Instagram page.

    My question is…..what can I add to the snippet code to make it open a new window?

  • Amber Eland

    I have no clue what so ever why this isnt working
    I have a child theme in place, and in that folder, and yes it is currently installed and active… all I have is the style.css and the functions.php

    this is what I have in my functions, and if you go to my site, you will see none of the links are working at all
    bloodeagle.net

    but if I mess up the code just a smidge, I get errors, so I know it is loading from this functions.php

    why isnt a single link working?

    • Daniela

      Amber,

      Mine wasn’t working either until I changed the page id numbers on the left side of the code and on the first line in the code (in the code it is in black font, before the green link and on the first line – mine were 18, 25, 20). The black page id numbers need to correspond to the original pages’ id number (this is in your Theme>Customize>Content>Front Page>Featured pages options>Home featured page one…two…three pages). So, they are not the same as the page id number of your pages or categories that you are linking the new page in the green font (mine were 11,12,13). The pages you linked in the Theme>Customize…will only show up if there is a problem with the code. Otherwise, they will link to the green links as the featured page.

      I don’t know if that makes sense, but here is my version from my code:

      • Daniela

        It seems that in my code I just wrote the “black” numbers I mentioned are coming up in red. Hope it helps.

  • Dan

    Hello – I am using the customizr theme to update a current website. I have tried implementing the above php to set a different destination url for the featured image, however it is not working. I’ve changed the appropriate page ids and links but still it’s defaulting to the “feature one” page that I used as a test.

    the site is live — http://macrodiver.com

    thanks for any help getting this resolved.

  • Jake

    Will this allow me to set the featured page to an external link? If so how do I get the “ID” for the external link?

  • ally lew

    Hi Nicholas,

    I have no coding knowledge at all and currently facing a problem, on how to link a category- called ‘Journal’ (blog posts) as a feature page 2 in my home page. How to change the default settings? I have read the above similar response, but have no clue as to how to do it step by step. Please help me , you can go to allylew.com

    Thanks Nicholas!

  • Rhonda

    Is there any way to add a link in the right sidebar that will take the user back to the Front Page of customizr theme? I know they can like on the title at the top but I would also like to add it to the nav menu in the sidebar.

    • Nicolas Post author

      Hi Rhonda,
      I would create a new menu in admin and include the home page in it. Then add this menu to the WP menu widget and assign this widget to the wanted sidebar location.
      Hope this helps

  • George Papadopoulos

    Hi,

    Is there any way to do the same thing for posts? I mean, when viewing a list of posts in a category page, I want to open a pdf file when clicking on a post. I already tried

    xxx => ‘http://mysite.com/yyy.pdf’,

    where the xxx is the page id of the post,
    but with no result at all.

    Best,
    George

      • Nicolas Post author

        Hi, I would recommend to use a post meta field to enter the url of the PDF.
        Then on your post list, instead of calling the get_permalink() function, use the get_post_meta() function.
        A good plugin to do this is Advanced Customi Fields.
        Hope this will help!

  • Brizzle

    Hi Nicolas,

    I’ve been trying to get HTML links to work in the three featured text areas on this site http://www.strandvilla.se/ for about a week and then came across this solution, so I’m trying to link the read more buttons to the URL’s they should match too, these links shouldn’t change.

    I added this code below to functions.php hoping it would help but it doesn’t seem to have come into effect, is there anything else I need to do?

    Thanks,
    Brizzle

  • Fernando Pont

    Bon jour, Nicolas… I am trying your beautiful theme but i have this strange behaviour occuring when I open a category from the menu (I.e. the “Blog” cat.):

    The title reads as this: Archivo Categorías: %s Blog (note the offending “%s” before the category name…)

    Tried on the permalinks side but did not find any anomalies, at least that I can see.

    What could I possibly be doing wrong?

    Besides that, thank you for an awesome theme!

  • Lena

    I cannot get the featured pages feature to work. Wish I could post a screen shot….In the CustomizIt menu, I have it enabled and there are 3 home page featured pages listed that seem to be hyperlinks but nothing happens when I click on them. How do I set the 3 featured pages and their images? Either the documentation is not descript enough or my Theme is broken. Please help!

  • Javi

    Hi,

    I need to implement this custom links for the featured pages but I’m very newbie on WordPress 🙁 . I’m trying to do it but nothing changes.

    Do I only need to change that number 2, 9 instead of my page ids? In fact, I need to use product url..

    Do I also need to change the numbers of the first line 10 ,2?

    For example, I have 3 featured pages and I need the second one is linked to “http://www.mysite.com/?product=box-1” How can I do that?

    Thanks!

  • Thomas Seaford

    Can this snippet be used to link to an external page? Or does it only link to posts within one’s own WP site?

  • Mark

    May i use this snippet for chosing blog-entries as a featured page? Will the “F. P. Unlimited” give me the option to select blog-entries without this snippet?

    Thanks
    Mark

  • Jeff

    Hi there

    First of all – thanks for a great them. I’m new to wordpress and this is the best one I’ve found!

    My question is – Can you set the one of the featured pages to display categories instead of pages at all?

    Keep up the good work 🙂

    Thanks
    Jeff

      • Pavel Skrabanek

        Hi Nicolas, this is most awesome. I had to use a little work around to achieve categories instead of featured pages links from the start page. I sure hope you implement this officially somewhen later. Best regards!

        • Nicolas Post author

          Hi Pavel thanks for this feedback.
          Feel free to post your work around, this will surely be interesting for other users of the theme.
          Best

          • Pavel Skrabanek

            Nothing fancy, just followed your instructions and instead of assigning a custom link by page id

            I replaced them with the category ids

            • Mike iLL

              Yes. Thank you much for this. I ended up doing a similar work-around adding the permalink to category. But the excerpt is pulled from the selected page, as opposed to the custom link, correct? Would that be different with the plug-in (when new version implemented)?

Comments are closed.