Community Forums › Forums › Archived Forums › General Discussion › Would "is_plugin_active" function be right for this purpose?
Tagged: facebook comments, has_shortcode
- This topic has 10 replies, 3 voices, and was last updated 9 years ago by
lvvvvvl.
-
AuthorPosts
-
February 1, 2016 at 8:24 pm #178117February 1, 2016 at 9:33 pm #178118
Victor Font
ModeratorIs_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 #178121lvvvvvl
ParticipantThanks 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 #178134Victor Font
ModeratorYou 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 #178142Brad Dalton
ParticipantYou could check using has_shortcode https://codex.wordpress.org/Function_Reference/has_shortcode
February 2, 2016 at 5:42 pm #178195lvvvvvl
ParticipantThanks 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 #178214lvvvvvl
ParticipantI'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 #178215Brad Dalton
ParticipantFebruary 2, 2016 at 9:53 pm #178217lvvvvvl
ParticipantI 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 #178218Brad Dalton
ParticipantNot 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/
February 2, 2016 at 10:18 pm #178220lvvvvvl
ParticipantI 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.
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.