Issues getting PHP to display in category pages


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 = ''.$crunchifyURL;
        $googleURL = ''.$crunchifyURL;
        $bufferURL = ''.$crunchifyURL.'&text='.$crunchifyTitle;
        $linkedInURL = ''.$crunchifyURL.'&title='.$crunchifyTitle;

        // Based on popular demand added Pinterest too
        $pinterestURL = ''.$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;
        // 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

 * The Category template file.
 * Permalink trouble
 * @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 -->                                          
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;
<a class="category-link" href="">🇦🇹</a>&nbsp;
<a class="category-link" href="">🇧🇪</a>&nbsp;
<a class="category-link" href="">🇧🇬</a>&nbsp;
<a class="category-link" href="">🇫🇷</a>&nbsp;
<a class="category-link" href="">🇩🇪</a>&nbsp;
<a class="category-link" href="">🇬🇧</a>&nbsp;
<a class="category-link" href="">🇭🇺</a>&nbsp;
<a class="category-link" href="">🇮🇹</a>&nbsp;
<a class="category-link" href="">🇯🇵</a>&nbsp;
<a class="category-link" href="">🇱🇺</a>&nbsp;
<a class="category-link" href=""> 🇵🇹</a>&nbsp;
<a class="category-link" href="">🇷🇴</a>&nbsp;
<a class="category-link" href=""> 🇺🇦</a>&nbsp;
<a class="category-link" href="">🇺🇸</a>&nbsp;</div>
                            <?php /* Start the Loop */ ?>
                            <?php while ( have_posts() ) : the_post(); ?>

                                     * Run the loop for the search to output the results.
                                    get_template_part( 'template-parts/content', 'category' );

                            <?php endwhile; ?>

                            <?php the_posts_navigation(); ?>

                    <?php else : ?>

                            <?php get_template_part( 'template-parts/content', 'none' ); ?>

                    <?php endif; ?>



        </main><!-- #main -->

    </section><!-- #primary -->

<?php get_footer(); ?>
, Obsidian 3 years 2019-10-06T09:41:39-05:00 0 Answers 77 views 0

Leave an answer