How To Get Template For WordPress Widget
Using the following snippet will let you get template for WordPress widget.
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 |
/* Plugin Name: Your Plugin Name Here Plugin URI: http://yourpluginsite.com Description: This displays your Blogs in your WP Network Author: The Author Name Here Version: 1.0.0 Author URI: http://theauthoraddress.com */ class My_Widget extends WP_Widget { public function __construct() { // widget actual processes } public function form( $instance ) { // outputs the options form on admin } public function update( $new_instance, $old_instance ) { // processes widget options to be saved } public function widget( $args, $instance ) { // outputs the content of the widget } } add_action( 'widgets_init', create_function( '', 'register_widget( "My_Widget" );' |
Snippet Source/Credit: Snipplr
How To Get WordPress Page Slug
The following snippet will let you get WordPress page slug.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
// 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 Have Custom Menus For Different Category/Page/Post
Thanks to the snippet below, one can now have custom menus for different categories, pages or posts.
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 |
<?php // add the following to wp theme function.php register_nav_menus( array( 'primary-menu' => 'main menu', 'marketing-menu' => 'marketing menu', 'shopping menu' => 'shopping menu', 'technology menu' => 'technology menu', 'recreation menu' => 'recreation menu', ) ); add_action( 'init', 'register_nav_menus' ); ?> <?php // add following to where you want the menu share, in my case, hearder.php <?php if((has_nav_menu('marketing-menu') and !is_home() and is_category(array(5,6,8,9,10,11,12,13,14))) or (has_nav_menu('marketing-menu') and !is_home() and in_category(array(5,6,8,9,10,11,12,13,14)))) { wp_nav_menu(array( 'theme_location' => 'marketing-menu', 'container' => '', 'menu_id' => 'primary-nav', 'container_class' => 'main-menu', 'menu_class' => 'nav' )); } else(has_nav_menu('primary-menu')){ wp_nav_menu(array( 'theme_location' => 'primary-menu', 'container' => '', 'menu_id' => 'primary-nav', 'container_class' => 'main-menu', 'menu_class' => 'nav' )); ?> |
Snippet Source/Credit: WordPress Code 1, 2, 3, 4
How To Have WordPress Domain Check
Using the following snippet will let you have your WordPress domain check.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<?php $loc = $_SERVER['REQUEST_URI']; $locDomain = $_SERVER['HTTP_HOST']; $posDomain = strpos($locDomain, 'travismathew.ca'); ?> <?php if ($posDomain !== false) { ?> <!-- CANADIAN --> <?php } else { ?> <!-- UNITED STATES --> <?php } ?> |
Snippet Source/Credit: Snipplr
How To Integrate The WordPress Media Uploader Into Your Plugin
Quite most of the time, you do require the need that you will be able to integrate the WordPress media uploader into your plugin. Well, this can be possibly done with the help of snippet below.
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 |
// PHP, adds the appropriate scripts and styles in admin add_action('admin_print_scripts',array(&$this,'uploader_scripts')); add_action('admin_print_styles',array(&$this,'uploader_styles')); public function uploader_scripts(){ wp_enqueue_script('media-upload'); wp_enqueue_script('thinkbox'); } public function uploader_styles(){ wp_enqueue_style('thickbox'); } // The html for the button and hidden input for result (super simple) <input id="backdrop_upload_button" value="Upload/Select Image" type="button" class="button" /> <input type="hidden" name="the_image" id="the_image" value="<?= $settings['the_image'] ?>" /> // The jQuery to open the media uploader and get the response var $ = jQuery; // Handels image uploading $(document).ready(function(){ $("input#upload_button").click(function(){ tb_show('','media-upload.php?type=image&post_id=1&TB_iframe=true&flash=0&backdrop=true'); return false; }) window.send_to_editor=function(html){ var img = $('<div>'+html+'</div>').find('img').attr('src'); $('#the_image').val(img); tb_remove(); }; }); |
Snippet Source/Credit: FatFolderDesign