Skip to content

Instantly share code, notes, and snippets.

View hemraj7171's full-sized avatar

Hemraj Adhikari hemraj7171

  • Web Experts Nepal(WEN)
  • Kathmandu,Nepal
View GitHub Profile
@hemraj7171
hemraj7171 / WP Config File Power
Last active July 20, 2016 08:48
Why wp-config.php file is so much important in WordPress
Use wp-config to better handle WordPress
1. Basic configuration
a) Database Configuration
2. Debugging
3. Security
a) Security Keys
define('AUTH_KEY', 'put your unique phrase here');
define('SECURE_AUTH_KEY', 'put your unique phrase here');
define('LOGGED_IN_KEY', 'put your unique phrase here');
define('NONCE_KEY', 'put your unique phrase here');
@hemraj7171
hemraj7171 / google-capcha-validation.js
Last active November 16, 2016 10:13
Validate Google Capcha before form submit
$("form").submit(function(event) {
var recaptcha = $("#g-recaptcha-response").val();
if (recaptcha === "") {
event.preventDefault();
alert("Please check the recaptcha");
}
});
@hemraj7171
hemraj7171 / user_registration_wp.php
Created November 17, 2016 14:28
Register new user on WordPress with role
/*
* Place this code on function.php or other included file on function.php
*/
//new user email
$email_address = 'hemraj7171@gmail.com';
//new manual password or generate password
//$password = wp_generate_password( 12, false );
$password = 'adminpassword';
//username
$username = 'hemraj7171';
@hemraj7171
hemraj7171 / price_range_query.php
Created December 15, 2016 11:47
Price Different Range Query
<?php
function product_price_loop( $priceArray ) {
$arr = array( 'relation' => 'OR' );
/*$output['output'] = print_pre($arr);
return $output; */
foreach( $priceArray as $key => $value ) {
$price_range = explode( '-', $value );
# code...
$arr[$key] = array(
@hemraj7171
hemraj7171 / test-page-template.php
Last active January 5, 2017 11:34
Display single post with slug on other pages
<?php
/*
* Template Name: Test Page
*
*/
//please change this as your wish
// you can inser the post slug which you want to render
$post_slug = 'the-new-post_slug';
@hemraj7171
hemraj7171 / scroll-to-specific-section-jquery.js
Created January 9, 2017 04:55
Scroll to specific page section according to url dynamically
/*Scroll down specific section when page load*/
//render current page URL
    var uri = window.location.toString();
// if URL contain '#'
    if (uri.indexOf("#") > 0) {
//save '#' url
        var hashValue = location.hash;
//remove '#' url for cleaning
// not necessary
        var clean_uri = uri.substring(0, uri.indexOf("#"));
@hemraj7171
hemraj7171 / after-complete-page-load-jquery.js
Created January 9, 2017 07:15
After page fully loaded jQuery
jQuery( function( $ ) {
$(window).bind("load", function() {
//after complete page load
});
});
@hemraj7171
hemraj7171 / jquery-wp-comment-validation.js
Last active January 11, 2017 09:18
Validate WordPress default comment form using jQuery Validation Plugin
// Step 1 enqueue jQuery Validation Plugin (http://cdn.jsdelivr.net/jquery.validation/1.15.0/jquery.validate.js) on function.php
// Step 2 enqueue jQuery this js file
// enjoy
jQuery(function($) {
$('#commentform').validate({
rules: {
author: {
required: true,
minlength: 2
@hemraj7171
hemraj7171 / list_last_2_days_posts.php
Created February 11, 2017 20:42
Display last 2 days posts on wordpress
//query args
$posts_args = array(
'posts_per_page' => 3,
'date_query' => array(
'after' => date('Y-m-d', strtotime('-2 days'))
)
);
$posts = get_posts( $posts_args );
//display posts
foreach ( $posts as $post ): setup_postdata( $post );
@hemraj7171
hemraj7171 / http_to_https_wordpres.txt
Last active February 13, 2017 06:58
HTTP to HTTPS WordPress
1. Install SSL licence into your domain
2. Run following migration query:
UPDATE wp_options SET option_value = replace(option_value, 'http://www.site.com', 'https://www.site.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://www.site.com','https://www.site.com');
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.site.com', 'https://www.site.com');
UPDATE wp_postmeta SET meta_value = replace(meta_value, 'http://www.site.com', 'https://www.site.com');
NOTE: please change the site with your domain and also change the table prefix if required
3. Add redirection rule on .htaccess file:
# Redirect HTTP to HTTPS
RewriteEngine On