If you want to add a new social option in the topbar of OceanWP, you may have seen the OceanWP documentation here. But it adds it at the end. You you wish to reorder the new social option, here is a little trick, by inserting the new option in the correct place in the array instead of adding it to the end. Code below to be added to your child theme functions.php file :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | // https://stackoverflow.com/questions/2149437/how-to-add-an-array-value-to-the-middle-of-an-associative-array function insertBeforeKey($array, $key, $data = null) { if (($offset = array_search($key, array_keys($array))) === false) // if the key doesn't exist { $offset = 0; // should we prepend $array with $data? $offset = count($array); // or should we append $array with $data? lets pick this one... } return array_merge(array_slice($array, 0, $offset), (array) $data, array_slice($array, $offset)); } /** * Add new social options in the Customizer */ function my_ocean_social_options( $array ) { // Thingiverse icon $array = insertBeforeKey($array, 'dribbble', array('thingiverse' => array( 'label' => 'Thingiverse', 'icon_class' => 'fa fa-cube', ))); // Return return $array; } add_filter( 'ocean_social_options', 'my_ocean_social_options' ); |
Thank you! I know it’s a bit outdated, and had to use a ‘close enough’ fa icon, but wanted to add Myspace to the array. Code worked perfectly (with minor alterations of swapping in Myspace in lieu of Thingiverse). Thanks, again!