• Resolved TheMadWiddler1200

    (@themadwiddler1200)


    I need to change the Featured Page Title and Links for my website but I can’t figure out a few things. I found these snippets on the themesandco website but I cant figure out what part of the code I should change to get what I want. If this were CSS I would just copy and paste to see what i get, but this is PHP, I’m kinda afraid of php because last time I made an error on one code and my whole site crashed. Got an error message every time i tried to log in or see my site. Don’t want to risk making another mistake again.

    These are the codes I need to add to my PHP file but I’m unsure what part I should change.

    To change the titles, this is the code I need to put in my PHP, but I don’t know what part of it to modify.

    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];
    }

    To change the links, this is the code I need to add. What part do I modify? Also where can I add the target=”_blank” to open in a new window?

    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'
            2 => 'https://www.my-custom-url-one.com',
            9 => 'https://www.my-custom-url-two.com'
        );
    
        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;
    }

    If you can answer my question I’d greatly appreciate it! Also please be as specific as possible. Thanks in advance.

Viewing 15 replies - 1 through 15 (of 15 total)
  • Thread Starter TheMadWiddler1200

    (@themadwiddler1200)

    Can anyone help me? This is one of the final problems I’m dealing with on my website. Once I get this sorted out, I can finally publish my site online.

    Thread Starter TheMadWiddler1200

    (@themadwiddler1200)

    I decided to try and change the codes on my own. Didn’t break my site! :p I added the code at the top for changing the links. I figured out what part of the code to modify. I changed the “2 – 9” to “page id’s” and added the url of the page I want it linked to. But nothing is happening, the links are staying the same in the featured pages. Is there something I’m missing? Do I also change the numbers “10 & 2”?? Any help I can get would be greatly appreciated!

    Thread Starter TheMadWiddler1200

    (@themadwiddler1200)

    I tried changing the same lines of code for the title’s snippet, but nothing is happening. What am I missing??!? Please, any help would be greatly appreciated!!!

    TheMadWiddler1200, if you’re scared to break your site you should try your changes in a local installation.
    That said, you have the right snippets.
    Also where you took those hooks is explained how to grab the page_id
    https://themesandco.com/snippet/setting-custom-links-featured-pages-customizr/
    what do you miss?
    About adding the _blank target, there isn’t a specific hook to add link attrs, but we can hack the second snippet changing this piece:

    //assigns a custom link by page id
        $custom_link = array(
            //page id => 'Custom link'
            2 => 'https://www.my-custom-url-one.com',
            9 => 'https://www.my-custom-url-two.com'
        );

    with this:

    //assigns a custom link by page id
        $custom_link = array(
            //page id => 'Custom link'
            2 => 'https://www.my-custom-url-one.com" target="_blank',
            9 => 'https://www.my-custom-url-two.com" target="_blank'
        );

    That should do the trick.

    No you don’t have to change those 10 and 2.
    Are you using an fp plugin?
    A link to your site?

    Thread Starter TheMadWiddler1200

    (@themadwiddler1200)

    Hi d4z_c0nf! Thanks for replying, really appreciate your help! ??

    I’m new to wordpress, what do you mean make changes in local installation?

    Also, I AM adding the page’s ID. I replaced the “2 – 9 ” with the pages id # but nothing is changing.

    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'
            814 => 'URL WHERE SITE WILL LINK TO',
            815 => 'URL WHERE SITE WILL LINK TO',
            816 => 'URL WHERE SITE WILL LINK TO'
        );
    
        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;
    }

    Am I missing something?

    Thread Starter TheMadWiddler1200

    (@themadwiddler1200)

    @d4z_c0nf

    I am not using an FP Plugin. Should I?? I would gladly link you to my site but it has nsfw pics on it. Don’t want to get in any trouble.

    Thread Starter TheMadWiddler1200

    (@themadwiddler1200)

    Wow, I should install the Featured Pages Customizer plugin for any code to work, shouldn’t I? If this is the problem, I’m gonna slap my self, hard, really effing hard! @d4z_c0nf should i install the plugin??

    No you should not use a fp plugin if you don’t want to. I asked just because those filters don’t work, without changing them a bit, with fp plugins.
    It’s weird, they should work.
    Just to know, did you selected the fp pages (I mean assign a real page ot any featured page) in Customize -> Content: home, posts… -> Front Page ?
    You should.
    I don’t care about nsfw, but if you don’t want to write a plain url, give me some keywords so I can find it on google ( can I? is t reachable through google? )

    Thread Starter TheMadWiddler1200

    (@themadwiddler1200)

    I really hoped that not having the plugin was the problem, if it was it would of been an easy fix. I did select featured pages, they are all linked to home. Should I remove this option, leave them blank? It’s not reachable through google, sorry. I really want to link you to my site, but I’m afraid I’ll get in trouble here for linking to an adult site. I really appreciate you trying to help.

    I’m sorry I cannot see what is happening..
    Anyway no, you don’t have to leave them blank, but if they are all linked to home then.. what are those 814 815 816 ?

    Thread Starter TheMadWiddler1200

    (@themadwiddler1200)

    I did it! I got it to work! The codes were working properly, i didn’t know I had to change the links in the customize menu. Even my titles now appear!

    Many thanks for your help, d4z_c0nf!!

    Np.
    Now you can use the “trick” I suggested to have target=_blank in your links.
    Glad you solved.
    Could you mark this topic as resolved?
    Thanks.

    Thread Starter TheMadWiddler1200

    (@themadwiddler1200)

    I had forgot about that! I just added your trick, it works like a charm! Thank you for all your help, d4z_c0nf!!!

    Np ??

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Change Featured Pages Title and Links.’ is closed to new replies.