Issues getting PHP to display in category pages

Question

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 = 'https://twitter.com/intent/tweet?text='.$crunchifyTitle.'&url='.$crunchifyURL.'&via=Crunchify';
        $facebookURL = 'https://www.facebook.com/sharer/sharer.php?u='.$crunchifyURL;
        $googleURL = 'https://plus.google.com/share?url='.$crunchifyURL;
        $bufferURL = 'https://bufferapp.com/add?url='.$crunchifyURL.'&text='.$crunchifyTitle;
        $linkedInURL = 'https://www.linkedin.com/shareArticle?mini=true&url='.$crunchifyURL.'&title='.$crunchifyTitle;

        // Based on popular demand added Pinterest too
        $pinterestURL = 'https://pinterest.com/pin/create/button/?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: http://crunchify.me/1VIxAsz -->';
        $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.
 *
 *
 * Permalink trouble https://codex.wordpress.org/Template_Hierarchy
 *
 * @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="https://www.obsidianurbexphotography.com/locations/">All</a>&nbsp;<a class="category-link" href="https://www.obsidianurbexphotography.com/locations/education/">Education</a>&nbsp;
<a class="category-link" href="https://www.obsidianurbexphotography.com/locations/industrial/">Industrial</a>&nbsp;
<a class="category-link" href="https://www.obsidianurbexphotography.com/locations/leisure/">Leisure</a>&nbsp;
<a class="category-link" href="https://www.obsidianurbexphotography.com/locations/medical/">Medical</a>&nbsp;
<a class="category-link" href="https://www.obsidianurbexphotography.com/locations/military/">Military</a>&nbsp;
<a class="category-link" href="https://www.obsidianurbexphotography.com/locations/other/">Other</a>&nbsp;
<a class="category-link" href="https://www.obsidianurbexphotography.com/locations/religious/">Religious</a>&nbsp;
<a class="category-link" href="https://www.obsidianurbexphotography.com/locations/residential/">Residential</a>&nbsp;
</br>
<a class="category-link" href="https://www.obsidianurbexphotography.com/locations/austria/">🇦🇹</a>&nbsp;
<a class="category-link" href="https://www.obsidianurbexphotography.com/locations/belgium/">🇧🇪</a>&nbsp;
<a class="category-link" href="https://www.obsidianurbexphotography.com/locations/bulgaria/">🇧🇬</a>&nbsp;
<a class="category-link" href="https://www.obsidianurbexphotography.com/locations/france/">🇫🇷</a>&nbsp;
<a class="category-link" href="https://www.obsidianurbexphotography.com/locations/germany/">🇩🇪</a>&nbsp;
<a class="category-link" href="https://www.obsidianurbexphotography.com/locations/great-britain/">🇬🇧</a>&nbsp;
<a class="category-link" href="https://www.obsidianurbexphotography.com/locations/hungary/">🇭🇺</a>&nbsp;
<a class="category-link" href="https://www.obsidianurbexphotography.com/locations/italy/">🇮🇹</a>&nbsp;
<a class="category-link" href="https://www.obsidianurbexphotography.com/locations/japan/">🇯🇵</a>&nbsp;
<a class="category-link" href="https://www.obsidianurbexphotography.com/locations/luxembourg/">🇱🇺</a>&nbsp;
<a class="category-link" href="https://www.obsidianurbexphotography.com/locations/portugal/"> 🇵🇹</a>&nbsp;
<a class="category-link" href="https://www.obsidianurbexphotography.com/locations/romania/">🇷🇴</a>&nbsp;
<a class="category-link" href="https://www.obsidianurbexphotography.com/locations/ukraine/"> 🇺🇦</a>&nbsp;
<a class="category-link" href="https://www.obsidianurbexphotography.com/locations/usa/">🇺🇸</a>&nbsp;</div>
</br>
                            <?php /* Start the Loop */ ?>
                            <?php while ( have_posts() ) : the_post(); ?>

                                    <?php
                                    /**
                                     * 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; ?>

                </div>

            </div>

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

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

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

Leave an answer

Browse
Browse