Речь пойдёт о добавлении дополнительного поля Vkontakte в консоли на странице профиля и выводе его в блоке Автор на странице поста. Отредактировать нужно 2 файла.
functions.php (корневая директория темы) - добавить строку:
function modify_user_contact_profile($profile_fields) {
// Add new fields
$profile_fields['facebook'] = __('Facebook URL', 'kotha');
$profile_fields['twitter'] = __('Twitter URL', 'kotha');
$profile_fields['gplus'] = __('Google+ URL', 'kotha');
$profile_fields['linkedin'] = __('Linkedin URL', 'kotha');
$profile_fields['tumblr'] = __('Tumblr URL', 'kotha');
$profile_fields['pinterest'] = __('Pinterest URL', 'kotha');
$profile_fields['vk'] = __('VKontakte URL', 'kotha');
return $profile_fields;
}
add_filter('user_contactmethods', 'modify_user_contact_profile');Если есть свой functions.php, для выведения полей можно добавить нужные строки в него:
function my_modify_user_contact_profile($profile_fields) {
// Add new fields
$profile_fields['vk'] = __('VKontakte URL', 'kotha');
return $profile_fields;
}
add_filter('user_contactmethods', 'my_modify_user_contact_profile');user-profile.php (wp-content\themes\kotha) - добавить код в соответствующих местах:
$vkLink = get_the_author_meta('vk');
//
<?php
if ( $vkLink ){
echo "<li><a href='".esc_url($vkLink)."'><i class='fa fa-vk'></i></a></li>";
}
?>Здесь <i class='fa fa-vk'></i> добавляется иконка шрифта Font Awesome. Если нужно добавить иконку Одноклассники, то класс будет следующий: fa fa-odnoklassniki
Редактирование файла social-icons.php добавляет поле в виджет Kotha Social Icons.
social-icons.php (wp-content\themes\kotha\inc\widgets) - добавить код в соответствующих местах:
$vk = ( isset( $instance['vk'] ) ) ? $instance['vk'] : '';
//
<p>
<label
for="<?php echo esc_attr( $this->get_field_id( 'vk' ) ); ?>"><?php _e( 'Enter VKontakte URL:', 'kotha' ); ?></label>
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'vk' ) ); ?>"
name="<?php echo esc_attr( $this->get_field_name( 'vk' ) ); ?>" type="text"
value="<?php echo esc_url( $vk ); ?>">
</p>
//
$instance['vk'] = ( ! empty( $new_instance['vk'] ) ) ? strip_tags( $new_instance['vk'] ) : '';
//
<?php $vk_link = $instance['vk'];
if ( $vk_link ) { ?>
<li><a href="<?php echo esc_url( $vk_link ) ?>" class="vk"><i
class="fa fa-vk"></i></a></li>
<?php } ?>Можно в дочерней теме файл social-icons.php вложить в соответствующую папку (wp-content\themes\kotha-child\inc\widgets) и в фале functions.php добавить строку:
require_once get_stylesheet_directory() . '/inc/widgets/social-icons.php';
Но тогда придётся удалить из файла functions.php родительской темы строку:
require_once get_template_directory() . '/inc/widgets/social-icons.php';