Wordpress friendly links are only displayed on the home page

Source: Internet
Author: User

Wordpress can set a chain table, and drag and drop the chain table widget in the background appearance tool to display the link on the sidebar. But how can we only display the link on the homepage, what about links not displayed on other pages? The source code is not modified, so that the tool can be used without creating a sidebar file.

Remove the widget from the sidebar

You only need to find the related filter. The hook of widgets in this sidebar is sidebars_widgets. If you want to display a widget without a link on a non-homepage, add the following code:

The code is as follows: Copy code


// Display the widget of the link on the homepage only
Function index_link ($ widgets ){
If (! Is_home ()){
Unset ($ widgets ['sidebar-1'] [8]);
 }
Return $ widgets;
}
Add_filter ('inclubars _ widgets', 'index _ link ');

Pay attention to the fourth line, to modify according to your own situation, here the sidebar name is called sidebar-1, array 8th key value for links to judge as a link, so it unset off it. How can we know which is the array of links?

The code is as follows: Copy code

// Display the widget of the link on the homepage only
Function index_link ($ widgets ){
Echo '<pre> ';
Var_dump ($ widgets );
If (! Is_home ()){
Unset ($ widgets ['sidebar-1'] [8]);
 }
Return $ widgets;
}
Add_filter ('inclubars _ widgets', 'index _ link ');

We only need to print out $ widgets to view the array and find the name of the sidebar used by the current topic. The key value of the chain table is link. After unset, it will be OK.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.