简体   繁体   中英

Where to add a filter in functions.php of my Wordpress theme?

On wordpress 4.9.1, the plugin Menu Social Icons is installed and the theme Twenty Sixteen is being used. The plugin works as expected, except for Stackoverflow and Vimeo icons. The problem is that for these two websites a generic icon will be shown, instead of the one corresponding to these sites.

In the documentation of the plugin it can be found that this issue is well known and they present the solution. However, due to my lack of php knowledge, I have not been able to make it work.

Their solution:

Option: Add Vimeo and Stack Exchange

To use FontAwesome 4.0+, which drops support for IE7, but adds vimeo.com and stackexchange.com, add this to your theme's functions.php file: add_filter( 'storm_social_icons_use_latest', '__return_true' );

I have tried including the line add_filter( 'storm_social_icons_use_latest', '__return_true' ); in different locations of the functions.php of my theme, without positive results.

Where would be the correct location to add this line of code in the php file?

In terms of their solution not working, I'd suggest that the issue probably isn't in your functions.php file, as all filter functions in your current functions.php file should work.
A couple of notes to consider though:

  • If you need to modify a WordPress theme, your best option is to create a " Child Theme " to make the changes in, otherwise your updates will be overwritten whenever your theme is updated.
  • Also, best practice when working on WordPress themes (or just PHP in general) is usually to add your changes at the bottom of the file you're modifying, after a comment to say what they are, and before the ?> .

A good example in this case would be to modify your functions.php file so it finishes like so:

  //function to include latest FontAwesome changes - 31/12/2017
  add_filter( 'storm_social_icons_use_latest', '__return_true' );

?>

Although, I can't stress to you how useful child themes are in situations like this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM