• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Would "is_plugin_active" function be right for this purpose?

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › Would "is_plugin_active" function be right for this purpose?

This topic is: not resolved

Tagged: facebook comments, has_shortcode

  • This topic has 10 replies, 3 voices, and was last updated 10 years, 1 month ago by lvvvvvl.
Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • February 1, 2016 at 8:24 pm #178117
    lvvvvvl
    Participant

    Hello,

    I recently installed a test plugin on my blog. I thought that a good way of making the tests popular might be by allowing facebook comments. The problem is I use the tests shortcode on Pages instead of Posts and I have comments disabled for all of my pages.

    I want to add facebook comments manually ONLY if this test plugin is active on that page. Would this be possible with the "is_plugin_active" function?

    Something like:

    
    remove_action( 'genesis_list_comments', 'genesis_default_list_comments' );
    remove_action( 'genesis_comment_form', 'genesis_do_comment_form' );
    add_action('genesis_comments', 'wpa_disqus_comments' );
    function wpa_disqus_comments() {
    if ( is_plugin_active( 'plugin-directory/plugin-file.php' ) ) {
    ?>
    <p><div class="fb-comments" data-href="<?php the_permalink(); ?>" data-width="100%" data-numposts="5" data-order-by="social" data-colorscheme="light"></div></p>
    <?php }
    }

    Thank you.

    February 1, 2016 at 9:33 pm #178118
    Victor Font
    Moderator

    Is_plugin_active only tests for whether a plugin has been activated or not. Plugins are activated on a site wide basis, not per page even though you may be using a plugin shortcode on one page. You should probably test for page ID with the is_page() function.


    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    February 1, 2016 at 9:41 pm #178121
    lvvvvvl
    Participant

    Thanks Victor for your response.

    The reason I wanted to use something like this rather than is_page is because I already have over 50 tests so adding the ID manually everytime would be really time consuming. Since there's no Category option for pages, I'm not sure exactly how I could group all these tests so as to load FB comments solely on these pages.

    Would there be some custom function or plugin (preferably function, to avoid extra plugin load baggage) I could use to do something like this?

    February 2, 2016 at 5:13 am #178134
    Victor Font
    Moderator

    You could add a custom field to the page and test for that field to activate your Facebook comments. You would only have to write the code once. You would only have to remember to add the field to the page when you create a new page.


    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    February 2, 2016 at 6:53 am #178142
    Brad Dalton
    Participant

    You could check using has_shortcode https://codex.wordpress.org/Function_Reference/has_shortcode


    Tutorials for StudioPress Themes.

    February 2, 2016 at 5:42 pm #178195
    lvvvvvl
    Participant

    Thanks guys for the suggestions, I'll try Brad's idea as it will involve less editing of existing pages. 🙂

    February 2, 2016 at 9:04 pm #178214
    lvvvvvl
    Participant

    I've added this as my function:

    remove_action( 'genesis_list_comments', 'genesis_default_list_comments' );
    remove_action( 'genesis_comment_form', 'genesis_do_comment_form' );
    add_action('genesis_comments', 'wpa_fb_comments' );
    function wpa_fb_comments() {
    if (has_shortcode('viralQuiz')) {
    ?>
    <h3>Comments</h3>
    <p><div class="fb-comments" data-href="<?php the_permalink(); ?>" data-width="100%" data-numposts="5" data-order-by="social" data-colorscheme="light"></div></p>
    <?php }
    }

    It doesn't seem to appear for some reason though. Is it because I didn't add the $content parameter?

    February 2, 2016 at 9:30 pm #178215
    Brad Dalton
    Participant

    Try this:

    if( has_shortcode( $content, 'viralQuiz' ) ) {

    Tutorials for StudioPress Themes.

    February 2, 2016 at 9:53 pm #178217
    lvvvvvl
    Participant

    I tried adding $content but it didn't work either. I thought maybe since I disabled comments in pages the genesis_comments hook wasn't working so I decided to add it to an existing manually implemented shortcode that is working at the bottom of pages (my advertisement and share buttons), I ended up with:

    add_action('genesis_entry_footer', 'tests_bottom', 1 );
    function tests_bottom() {
    if (is_page()) {
    echo do_shortcode('[the_ad id="xxx"]<br />');
    echo do_shortcode('<div class="sharer">Enjoyed This? Share It!</div>[easy-social-share buttons="facebook,twitter,stumbleupon,mail" counters=1 counter_pos="hidden" total_counter_pos="rightbig" style="button" twitter_user=""]');
    if( has_shortcode( $content, 'viralQuiz' ) ) {
    ?>
    <h3>Comments</h3>
    <p><div class="fb-comments" data-href="<?php the_permalink(); ?>" data-width="100%" data-numposts="5" data-order-by="social" data-colorscheme="light"></div></p>
    <?php }
    if ( function_exists( 'get_yuzo_related_posts' ) ) {
    get_yuzo_related_posts();
    }
    }
    }

    They FB comments still don't appear, though neither does the Yuzo Related posts work on pages for some reason, yet the exact same code when applied to is_single does.

    February 2, 2016 at 10:07 pm #178218
    Brad Dalton
    Participant

    Not sure how you have installed Facebook comments but you might find this helpful http://wpsites.net/tools/how-to-manually-install-facebook-comments-in-any-theme/


    Tutorials for StudioPress Themes.

    February 2, 2016 at 10:18 pm #178220
    lvvvvvl
    Participant

    I wrote a script that loads the facebook library on a 3 second delay using javascript on every page. But it can't be that as even if the FB comment loading was failing, it would at least display the H3 Comments title which it doesn't. It only loads the Advertisement and Social Buttons and nothing under that.

  • Author
    Posts
Viewing 11 posts - 1 through 11 (of 11 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble