• Welcome to WordPress

    One of my friends told me wanted to learn how to develop for WordPress. My reply was it’s very easy just go to the codex and start. Having said that and having sent him on his merry way. I realized maybe I have sent him on the wrong path, while the codex is the holy book of wordpress from which to start but a new developer might easily wander of the correct path. So keeping that in mind I hope that this post sends any newbie developers out there on the correct path. I assume that you know how to

    …Read More

  • Custom Post Type with Custom Meta Boxes Part 1 of 2

    First lets start with registering a custom post type, to be used at our discretion.There are 5 basic post_types that comes with wordpress these are not to be messed with. They are : Post (Post Type: ‘post’) Page (Post Type: ‘page’) Attachment (Post Type: ‘attachment’) Revision (Post Type: ‘revision’) Navigation menu (Post Type: ‘nav_menu_item’) If you use woocommerce you’ll see that basically they also use post_types. For now lets go with something easy. So the best(simplest) example that i could think of is with a custom photo gallery: You set your featured image there and add text there and it

    …Read More

  • WordPress Backend: Add Custom Field to Users Page

    So this is to add a custom field to your wordpress users page on the admin side. For well a plethora of things come to mind, if you want to show custom usermeta and make them editatble on the back end i’m guessing this would be pretty useful no? Ok the first part the function digthis_add_custom_fields just basically outputs the form and everything else required to show your field on the back end. <?php function digthis_add_custom_fields( $user ) {?> <h3><?php _e(‘Maintenance’, ‘twentythirteen’); ?></h3> <table class=”form-table”> <tr> <th> <label for=””><?php _e(‘Digthis Custom Field’, ‘twentythirteen’); ?> </label></th> <td> <input id=”my_id’  type=’text’ name=”fbname”

    …Read More

  • WordPress: Making Ajax Calls

    Just Like i promised, today we will cover making Ajax Calls Well lets start with the basics shall we? Each request needs to supply at least one piece of data (using the GET or POST method) called action. Based on this action, the code in admin-ajax.php creates two hooks, wp_ajax_my_action and wp_ajax_nopriv_my_action, wheremy_action is the value of the GET or POST variable action. Adding a function to the first hook means that that function will fire if a logged-in user initiates the action. Using the second hook, you can cater to logged-out users separately. add_action( ‘wp_enqueue_scripts’, ‘my_script_enqueuer’ ); function my_script_enqueuer()

    …Read More

  • Sync Roles of Multisite Users

    So this happened at work today, was working on a multiste and the client required that under a certain condition. For now lets say the condition is that I’m subscribing to the site and for 5 days i’m a free user on the 5th day i need the client to revert to role => unpaid. In my functions.php file i have this code function mysite_sync_site_roles($user_id = NULL) { // is_multisite() used just as precaution, this code is meant to Multisite only if( !is_multisite()) return; // Initial data $user_info = get_userdata( $user_id ); if(in_array(‘administrator’, $user_info->roles)) return; $blogs = get_blogs_of_user( $user_id );

    …Read More

  • Understanding The WordPress Template Hierarchy

    Template Hierarchy: 1)      Which template files will WordPress use when it displays a certain type of page? The General Idea WordPress uses the Query String — information contained within each link on your web site — to decide which template or set of templates will be used to display the page. First, WordPress matches every Query String to query types — i.e. it decides what type of page (a search page, a category page, the home page etc.) is being requested. Example https://www.digamberpradhan.com.np/?s=asdf this hyperlink will result in a  search page. Templates are then chosen — and web page content is generated

    …Read More

  • How to use PHP Data in your Javascript files for WordPress

    WordPress makes it spectacularly easy to transfer data to you javascript files if you’re unfamiliar with enqueuing scripts then please refer to my previous post. Here it goes then. Say you want to do something “fancy” like ajax calls from you js files. I’m starting to get a little off point here right now i’d like to fully explore only localization. So ajax calls will be covered in a later post (hopefully soon) You’ll need to use wp_localize_script to make data availabe to javascript. Syntax: wp_localize_script( $handle, $name, $data ); Example add_action(‘wp_enqueue_scripts’,’digthis_loadscript’); function digthis_loadscript() { wp_register_script( ‘main’, get_template_directory_uri(). ‘/js/main.js’, ”,

    …Read More

  • Correctly Enqueuing Styles and Scripts in WordPress

    Understand how to and more importantly why to register and enqueue your scripts and stylesheets in wordpress. If you do that then you’ll begin to understand the power and ease with which you can do much more creative things and create interactive webpages

    …Read More