php 自定义社交媒体图标

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 自定义社交媒体图标相关的知识,希望对你有一定的参考价值。

<?php
/*
Description: Displays basic social media icons
Author: <a href="http://coding.kristarae.co">Krista Rae</a>
*/

function display_social_icons($content) {

	if ( get_theme_mod( 'bloglovin_link', '' ) !== '' ) {
		$bloglovin = get_theme_mod( 'bloglovin_link', '' );
		$content .= "<a href='{$bloglovin}' target='_blank'><i class='fa fa-heart'></i></a>";
	}

	if ( get_theme_mod( 'dribbble_link', '' ) !== '' ) {
		$dribbble = get_theme_mod( 'dribbble_link', '' );
		$content .= "<a href='{$dribbble}' target='_blank'><i class='fa fa-dribbble'></i></a>";
	}

	if ( get_theme_mod( 'email_link', '' ) !== '' ) {
		$email = get_theme_mod( 'email_link', '' );
		$content .= "<a href='{$email}' target='_blank'><i class='fa fa-envelope'></i></a>";
	}

	if ( get_theme_mod( 'facebook_link', '' ) !== '' ) {
		$facebook = get_theme_mod( 'facebook_link', '' );
		$content .= "<a href='{$facebook}' target='_blank'><i class='fa fa-facebook'></i></a>";
	}

	if ( get_theme_mod( 'flickr_link', '' ) !== '' ) {
		$flickr = get_theme_mod( 'flickr_link', '' );
		$content .= "<a href='{$flickr}' target='_blank'><i class='fa fa-flickr'></i></a>";
	}

	if ( get_theme_mod( 'github_link', '' ) !== '' ) {
		$github = get_theme_mod( 'github_link', '' );
		$content .= "<a href='{$github}' target='_blank'><i class='fa fa-github'></i></a>";
	}

	if ( get_theme_mod( 'googleplus_link', '' ) !== '' ) {
		$googleplus = get_theme_mod( 'googleplus_link', '' );
		$content .= "<a href='{$googleplus}' target='_blank'><i class='fa fa-google-plus-official'></i></a>";
	}

	if ( get_theme_mod( 'instagram_link', '' ) !== '' ) {
		$instagram = get_theme_mod( 'instagram_link', '' );
		$content .= "<a href='{$instagram}' target='_blank'><i class='fa fa-instagram'></i></a>";
	}

	if ( get_theme_mod( 'pinterest_link', '' ) !== '' ) {
		$pinterest = get_theme_mod( 'pinterest_link', '' );
		$content .= "<a href='{$pinterest}' target='_blank'><i class='fa fa-pinterest'></i></a>";
	}

	if ( get_theme_mod( 'rss_link', '' ) !== '' ) {
		$rss = get_theme_mod( 'rss_link', '' );
		$content .= "<a href='{$rss}' target='_blank'><i class='fa fa-rss'></i></a>";
	}

	if ( get_theme_mod( 'stumbleupon_link', '' ) !== '' ) {
		$stumbleupon = get_theme_mod( 'stumbleupon_link', '' );
		$content .= "<a href='{$stumbleupon}stumbleupon' target='_blank'><i class='fa fa-stumbleupon'></i></a>";
	}

	if ( get_theme_mod( 'tumblr_link', '' ) !== '' ) {
		$tumblr = get_theme_mod( 'tumblr_link', '' );
		$content .= "<a href='{$tumblr}' target='_blank'><i class='fa fa-tumblr'></i></a>";
	}

	if ( get_theme_mod( 'twitter_link', '' ) !== '' ) {
		$twitter = get_theme_mod( 'twitter_link', '' );
		$content .= "<a href='{$twitter}' target='_blank'><i class='fa fa-twitter'></i></a>";
	}

	if ( get_theme_mod( 'vimeo_link', '' ) !== '' ) {
		$vimeo = get_theme_mod( 'vimeo_link', '' );
		$content .= "<a href='{$vimeo}' target='_blank'><i class='fa fa-vimeo'></i></a>";
	}

	if ( get_theme_mod( 'youtube_link', '' ) !== '' ) {
		$youtube = get_theme_mod( 'youtube_link', '' );
		$content .= "<a href='{$youtube}' target='_blank'><i class='fa fa-youtube'></i></a>";
	}

	return $content;

}

//* Genesis setup function
// Link to plugins
require_once ('includes/social-icons.php');


//* Use within a function
$content .= display_social_icons($c);

//* If Font Awesome isn't already loaded
//* Enqueue Font Awesome
add_action( 'wp_enqueue_scripts', 'olivia_font_awesome' );
function olivia_font_awesome() {

	wp_enqueue_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css' );

}
//* Adds social media link options
function maryellen_social_media_customizer( $wp_customize ) {

    $wp_customize->add_section(
        'social_media_section',
        array(
            'title' => 'Social Media Links',
            'description' => 'Your social media links.',
            'priority' => 35,
        )
    );

    // Bloglovin' link
    $wp_customize->add_setting( 'bloglovin_link' );
    $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'bloglovin_link', array(
            'label'   => 'Bloglovin',
            'section' => 'social_media_section',
            'settings'   => 'bloglovin_link',
            'priority' => 1
    ) ) );

    // Dribbble link
    $wp_customize->add_setting( 'dribbble_link' );
    $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'dribbble_link', array(
            'label'   => 'Dribbble',
            'section' => 'social_media_section',
            'settings'   => 'dribbble_link',
            'priority' => 2
    ) ) );

    // Email link
    $wp_customize->add_setting( 'email_link' );
    $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'email_link', array(
            'label'   => 'Email',
            'description' => 'Example: mailto:hey@codedcreative.co',
            'section' => 'social_media_section',
            'settings'   => 'email_link',
            'priority' => 3
    ) ) );

    // Facebook link
    $wp_customize->add_setting( 'facebook_link' );
    $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'facebook_link', array(
            'label'   => 'Facebook',
            'section' => 'social_media_section',
            'settings'   => 'facebook_link',
            'priority' => 4
    ) ) );


    // Flickr link
    $wp_customize->add_setting( 'flickr_link' );
    $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'flickr_link', array(
            'label'   => 'Flickr',
            'section' => 'social_media_section',
            'settings'   => 'flickr_link',
            'priority' => 5
    ) ) );

    // Github link
    $wp_customize->add_setting( 'github_link' );
    $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'github_link', array(
            'label'   => 'Github',
            'section' => 'social_media_section',
            'settings'   => 'github_link',
            'priority' => 6
    ) ) );

    // Google+ link
    $wp_customize->add_setting( 'googleplus_link' );
    $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'googleplus_link', array(
            'label'   => 'Google+',
            'section' => 'social_media_section',
            'settings'   => 'googleplus_link',
            'priority' => 7
    ) ) );

    // Instagram link
    $wp_customize->add_setting( 'instagram_link' );
    $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'instagram_link', array(
            'label'   => 'Instagram',
            'section' => 'social_media_section',
            'settings'   => 'instagram_link',
            'priority' => 7
    ) ) );

    // Pinterest link
    $wp_customize->add_setting( 'pinterest_link' );
    $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'pinterest_link', array(
            'label'   => 'Pinterest',
            'section' => 'social_media_section',
            'settings'   => 'pinterest_link',
            'priority' => 8
    ) ) );

    // RSS link
    $wp_customize->add_setting( 'rss_link' );
    $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'rss_link', array(
            'label'   => 'RSS',
            'section' => 'social_media_section',
            'settings'   => 'rss_link',
            'priority' => 9
    ) ) );

    // StumbleUpon link
    $wp_customize->add_setting( 'stumbleupon_link' );
    $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'stumbleupon_link', array(
            'label'   => 'StumbleUpon',
            'section' => 'social_media_section',
            'settings'   => 'stumbleupon_link',
            'priority' => 10
    ) ) );

    // Tumblr link
    $wp_customize->add_setting( 'tumblr_link' );
    $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'tumblr_link', array(
            'label'   => 'Tumblr',
            'section' => 'social_media_section',
            'settings'   => 'tumblr_link',
            'priority' => 11
    ) ) );

    // Twitter link
    $wp_customize->add_setting( 'twitter_link' );
    $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'twitter_link', array(
            'label'   => 'Twitter',
            'section' => 'social_media_section',
            'settings'   => 'twitter_link',
            'priority' => 12
    ) ) );

    // Vimeo link
    $wp_customize->add_setting( 'vimeo_link' );
    $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'vimeo_link', array(
            'label'   => 'Vimeo',
            'section' => 'social_media_section',
            'settings'   => 'vimeo_link',
            'priority' => 13
    ) ) );

    // YouTube link
    $wp_customize->add_setting( 'youtube_link' );
    $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'youtube_link', array(
            'label'   => 'YouTube',
            'section' => 'social_media_section',
            'settings'   => 'youtube_link',
            'priority' => 14
    ) ) );

}
add_action( 'customize_register', 'maryellen_social_media_customizer' );

以上是关于php 自定义社交媒体图标的主要内容,如果未能解决你的问题,请参考以下文章

php Facebook,Twitter,Google Plus和LinkedIn的自定义社交分享图标

scss Wordpress的自定义社交分享按钮

Ruby on Rails 中的社交媒体共享按钮

如何在php中为json api实现缓存系统

最详细的个人博客教程搭建教程,最快5分钟快速搭建简约风格博客

php 社交媒体链接小工具与图标