How To Display Twitter Feed In WordPress
The following snippet will let you display Twitter feed in WordPress.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?php include_once(ABSPATH . WPINC . '/feed.php'); $rss = fetch_feed('https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=smashingmag'); $maxitems = $rss->get_item_quantity(3); $rss_items = $rss->get_items(0, $maxitems); ?> <ul> <?php if ($maxitems == 0) echo '<li>No items.</li>'; else // Loop through each feed item and display each item as a hyperlink. foreach ( $rss_items as $item ) : ?> <li> <a href='<?php echo $item->get_permalink(); ?>'> <?php echo $item->get_title(); ?> </a> </li> <?php endforeach; ?> </ul> |
Snippet Source/Credit: Smashing Magazine
How To Execute Shortcode From Custom Field
The snippet will let you add shortcode to a WordPress custom field while by default; the option is not available by WordPress.
1 |
<?php echo apply_filters('the_content', get_post_meta($post->ID, 'your_custom_field_here', true)); ?> |
Snippet Source/Credit: Leeboyce.co.uk
How To Get WordPress Page Slug
The following snippet will let you get WordPress page slug.
1 2 3 4 5 6 7 |
// Put in Functions.php function the_slug() { $post_data = get_post($post->ID, ARRAY_A); $slug = $post_data['post_name']; return $slug; } // Put where you want to show in page or single etc. Use for custom class for each page <?php echo the_slug(); ?> |
Snippet Source/Credit: Snipplr
How To Add Custom WordPress Settings
Using the following snippet, you will be able to add custom WordPress settings.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
/** * Wordpress add custom setting * Place this in functions.php file of your template. * */ function custom_settings() { ?> <form method="POST" action="options.php"> <?php settings_fields( 'custom-settings' ); //pass slug name of page, also referred //to in Settings API as option group name do_settings_sections( 'custom-settings' ); //pass slug name of page submit_button(); ?> </form> <?php } // add menu button add_action('admin_menu', 'plugin_admin_add_page'); function plugin_admin_add_page() { add_options_page('Custom Plugin Page', 'Custom Plugin Menu', 'manage_options', 'custom-settings', 'custom_settings'); } // This tells WordPress to call the function named "setup_theme_admin_menus" // when it's time to create the menu pages. // add_action("admin_menu", "setup_theme_admin_menus"); function eg_settings_api_init() { // Add the section to reading settings so we can add our // fields to it add_settings_section( 'eg_setting_section', 'Example settings section in reading', 'eg_setting_section_callback_function', 'custom-settings' ); // Add the field with the names and function to use for our new // settings, put it in our new section add_settings_field( 'eg_setting_name', 'Example setting Name', 'eg_setting_callback_function', 'custom-settings', 'eg_setting_section' ); // Register our setting so that $_POST handling is done for us and // our callback function just has to echo the <input> register_setting( 'custom-settings', 'eg_setting_name' ); } // eg_settings_api_init() add_action( 'admin_init', 'eg_settings_api_init' ); // ------------------------------------------------------------------ // Settings section callback function // ------------------------------------------------------------------ // // This function is needed if we added a new section. This function // will be run at the start of our section // function eg_setting_section_callback_function() { echo '<p>Intro text for our settings section</p>'; } // ------------------------------------------------------------------ // Callback function for our example setting // ------------------------------------------------------------------ // // creates a checkbox true/false option. Other types are surely possible // function eg_setting_callback_function() { echo '<input name="eg_setting_name" id="gv_thumbnails_insert_into_excerpt" type="checkbox" value="1" class="code" ' . checked( 1, get_option( 'eg_setting_name' ), false ) . ' /> Explanation text'; |
Snippet Source/Credit: Snipplr
How To Add Facebook Comments In Your Website
Using the following line of codes below, you will be able to add Facebook comments in your website.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
<div id="fb-root"></div> <script>(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=Your App ID Here"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));</script> <meta property="fb:app_id" content="Your App ID Here"/> <div class="fb-comments" data-href="<?php the_permalink() ?>" data-num-posts="2" data-width="470" data-colorscheme="light" data-mobile="false"></div> // Get combined FB and WordPress comment count function get_full_comment_count() { global $post; $url = get_permalink($post->ID); $filecontent = file_get_contents('https://graph.facebook.com/?ids=' . $url); $json = json_decode($filecontent); $count = $json->$url->comments; $wpCount = get_comments_number(); $realCount = $count + $wpCount; if ($realCount == 0 || !isset($realCount)) { $realCount = 0; } return $realCount; } function the_full_comment_count() { $realCount = get_full_comment_count(); echo $realCount; } |
Snippet Source/Credit: TutsPlus