admin管理员组

文章数量:1410697

I am using this code to display social media share links at the top of my posts. Currently, they display fine on my pages and posts. Is there any way to get this to display also on my category pages? Another option that would work is getting the code to display everywhere below the H1 and content, I don't think there are any pages where I don't want these buttons so perhaps this is the easier solution.

Any guidance would be greatly appreciated ☺️

function crunchify_social_sharing_buttons($content) {
    global $post;
    if(is_singular() || is_home()){

        // Get current page URL 
        $crunchifyURL = urlencode(get_permalink());

        // Get current page title
        $crunchifyTitle = htmlspecialchars(urlencode(html_entity_decode(get_the_title(), ENT_COMPAT, 'UTF-8')), ENT_COMPAT, 'UTF-8');
        // $crunchifyTitle = str_replace( ' ', '%20', get_the_title());

        // Get Post Thumbnail for pinterest
        $crunchifyThumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );

        // Construct sharing URL without using any script
        $twitterURL = '='.$crunchifyTitle.'&url='.$crunchifyURL.'&via=Crunchify';
        $facebookURL = '.php?u='.$crunchifyURL;
        $googleURL = '='.$crunchifyURL;
        $bufferURL = '='.$crunchifyURL.'&text='.$crunchifyTitle;
        $linkedInURL = ';url='.$crunchifyURL.'&title='.$crunchifyTitle;

        // Based on popular demand added Pinterest too
        $pinterestURL = '/?url='.$crunchifyURL.'&media='.$crunchifyThumbnail[0].'&description='.$crunchifyTitle;

        // Add sharing button at the end of page/page content
        $variable .= '<!-- Implement your own social sharing buttons without any JavaScript loading. No plugin required. Detailed steps here:  -->';
        $variable .= '<div class="crunchify-social">';
        $variable .= '<a class="crunchify-link crunchify-twitter" href="'. $twitterURL .'" target="_blank">Twitter</a>';
        $variable .= '<a class="crunchify-link crunchify-facebook" href="'.$facebookURL.'" target="_blank">Facebook</a>';
        $variable .= '<a class="crunchify-link crunchify-googleplus" href="'.$googleURL.'" target="_blank">Google+</a>';
        $variable .= '<a class="crunchify-link crunchify-buffer" href="'.$bufferURL.'" target="_blank">Buffer</a>';
        $variable .= '<a class="crunchify-link crunchify-linkedin" href="'.$linkedInURL.'" target="_blank">LinkedIn</a>';
        $variable .= '<a class="crunchify-link crunchify-pinterest" href="'.$pinterestURL.'" data-pin-custom="true" target="_blank">Pin It</a>';
        $variable .= '</div>';

        return $variable.$content;
    }else{
        // if not a post/page then don't include sharing button
        return $variable.$content;
    }
};
add_filter( 'the_content', 'crunchify_social_sharing_buttons');

Here is my category.php, as requested

<?php
/**
 * The Category template file.
 *
 *
 * @link 
 *
 * @package Zeal
 */

get_header(); ?>

    <section id="primary" class="content-area">

        <main id="main" class="site-main" role="main">

            <div class="container archive-page">

                <div class="row">

                    <?php if ( have_posts() ) : ?>

                            <header class="page-header">
                                <h1 class="page-title"><h1><?php single_cat_title(); ?></h1>
                            </header><!-- .page-header -->                                          
<?php 
the_archive_description( '<div class="taxonomy-description">', '</div>' ); 
?>
<hr class="wp-block-separator">
<div id="category-menu"><a class="category-link" href="/">All</a>&nbsp;<a class="category-link" href="/">Education</a>&nbsp;
<a class="category-link" href="/">Industrial</a>&nbsp;
<a class="category-link" href="/">Leisure</a>&nbsp;
<a class="category-link" href="/">Medical</a>&nbsp;
<a class="category-link" href="/">Military</a>&nbsp;
<a class="category-link" href="/">Other</a>&nbsp;
<a class="category-link" href="/">Religious</a>&nbsp;
<a class="category-link" href="/">Residential</a>&nbsp;
</br>
<a class="category-link" href="/">

本文标签: templatesIssues getting PHP to display in category pages