function_exists in PHP WordPress is not working for my theme

I am trying to developing a WordPress theme. I am using a function that is declared in a WordPress plugin. I declared another function in my theme and I want to my theme function when the plugin is not active. So I write the following code:

<?php
    if (function_exists(shaplatools_post_thumbnail_gallery())) {

        shaplatools_post_thumbnail_gallery();

    } else {
        boishakhimela_post_thumbnail();
    }
?>

But when the plugin is not activated it is showing the following error:

Read More

Fatal error: Call to undefined function shaplatools_post_thumbnail_gallery() in /var/www/wordpress/wp-content/themes/boishakhimela/content-page.php on line 11

the content of shaplatools_post_thumbnail_gallery() is as following:

function shaplatools_post_thumbnail_gallery() {
    if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) {
        return;
    }

    if ( is_singular() ) :

        $image_gallery = get_post_meta( get_the_ID(), '_shaplatools_image_gallery', true );

        if( ! empty( $image_gallery ) ) :

            ?>
                <div class="post-thumbnail">
                    <?php
                        if( function_exists( 'shaplatools_image_gallery' ) ) {
                            echo shaplatools_image_gallery();
                        }
                    ?>
                </div>
            <?php

        else : 
            ?>
                <div class="post-thumbnail">
                    <?php 
                        if ( has_post_thumbnail() ) {
                            the_post_thumbnail();
                        } 
                    ?>
                </div><!-- .post-thumbnail -->
            <?php
        endif;
        ?>
    <?php else : ?>
        <a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true">
            <?php
                the_post_thumbnail( 'post-thumbnail', array( 'alt' => get_the_title() ) );
            ?>
        </a>

    <?php endif; // End is_singular()
}

So how can I fix this problem?

Related posts

Leave a Reply

1 comment

  1. You should use: function_exists("shaplatools_post_thumbnail_gallery")

    You need to pass the function name as a string, see http://php.net/function_exists which states

    Parameters
    function_name
    The function name, as a string.

    If you’d use function_exists(shaplatools_post_thumbnail_gallery()) then you are actually calling the function shaplatools_post_thumbnail_gallery() and using it’s return value as argument of function_exists()