Skip to content

Instantly share code, notes, and snippets.

View chinmayrajyaguru's full-sized avatar
🎯
Focusing

Chinmay Rajyaguru chinmayrajyaguru

🎯
Focusing
View GitHub Profile
@chinmayrajyaguru
chinmayrajyaguru / create_wordpress_login_form_shortcode.php
Last active May 21, 2021 10:04 — forked from Njengah/create_wordpress_login_form_shortcode.php
Create Custom WordPress login form using Shortcode
// Step 1: Create shortcode
function njengah_add_login_shortcode() {
add_shortcode( 'jay-login-form', 'njengah_login_form_shortcode' );
}
//Step 2: Shortcode callback
function njengah_login_form_shortcode() {
if (is_user_logged_in())
return '<p>Welcome. You are logged in!</p>'; ?>
<div class ="njengah-login-tutorial" >
<?php return wp_login_form(
@chinmayrajyaguru
chinmayrajyaguru / wordpress-w3tc-site.conf
Created April 10, 2017 15:54 — forked from elivz/wordpress-w3tc-site.conf
Nginx configuration for WordPress with W3 Total Cache plugin. See http://elivz.com/blog/single/wordpress_with_w3tc_on_nginx/
server {
# Redirect yoursite.com to www.yoursite.com
server_name yoursite.com;
rewrite ^(.*) http://www.yoursite.com$1 permanent;
}
server {
# Tell nginx to handle requests for the www.yoursite.com domain
server_name www.yoursite.com;
@chinmayrajyaguru
chinmayrajyaguru / call-recent-comments.php
Last active March 22, 2017 13:16
WordPress Approved Recent Comments with Gavtar
<h3>Recent Comments</h3>
<ul class="recent-comment">
<?php
$comments =get_comments( array('number'=>'5', 'status' => 'approve') );
foreach($comments as $comm) :
$url = '<a href="'. get_permalink($comm->comment_post_ID).'#comment-'.$comm->comment_ID .'" title="'.$comm->comment_author .' | '.get_the_title($comm->comment_post_ID).'">' . $comm->comment_author . '</a>';
?>
<li>
<?php echo get_avatar($comm->comment_author_email, 30); ?>
<strong><?php echo $url; ?></strong>
@chinmayrajyaguru
chinmayrajyaguru / remove-wordpress-query-strings.php
Created June 28, 2016 20:44
Remove WordPress Query Strings From Static Resources
#add this to functions.php
function _remove_query_strings_1( $src ){
$rqs = explode( '?ver', $src );
return $rqs[0];
}
if ( is_admin() ) {
// Remove query strings from static resources disabled in admin
}
else {
@chinmayrajyaguru
chinmayrajyaguru / restart-server.sh
Created June 27, 2016 03:33
Restart nginx, mysql & php7.0-fpm [LEMP Users]
#If you installed / updated / changed anything on live server then this might be helpful!
#test nginx
sudo nginx -t
#restart nginx, mysql & php7.0-fpm
sudo systemctl reload nginx
sudo service mysql restart
systemctl restart php7.0-fpm.service
@chinmayrajyaguru
chinmayrajyaguru / wordpress-directories-file-permissions.sh
Created June 27, 2016 03:07
Proper WordPress Filesystem Permissions And Ownerships
#I Recommend
sudo find . -type d -exec chmod 755 {} \; #for all directories
sudo find . -type f -exec chmod 644 {} \; #for all files
sudo chmod 444 wp-config.php #change permission for this file only!
# For nginx users /var/www/html/
sudo chmod 444 wp-config.php
sudo chmod 444 nginx.conf
@chinmayrajyaguru
chinmayrajyaguru / changing-the-wordpress-site-url.sql
Last active June 27, 2016 02:38
Change the WordPress siteurl & home URL using MySQL command line
/* When moving sites from one location to another, it is sometimes necessary to manually modify data in the database to make the new site URL information to be recognized properly. Many tools exist to assist with this, but generally I use this method */
-- Login to MySQL
use database;
show tables;
SELECT *
-> FROM `wp_options`
-> LIMIT 0 , 30;
update wp_options set option_value = 'http://example.com OR http://Server_IP' where option_id = 1; -- Most important to pick correct option_id for change "siteurl" option_value
update wp_options set option_value = 'http://example.com OR http://Server_IP' where option_id = 1; -- Use this command again to change "home" option_value
EXIT
@chinmayrajyaguru
chinmayrajyaguru / example-import.sql
Last active June 27, 2016 02:11
Import MySQL database through command line
/* A common use of mysqldump is for making a backup of an entire database: */
CREATE DATABASE database-name DEFAULT CHARACTER SET utf8 COLLATE utf8_uni code_ci; -- Create new DB if you don't have it.
GRANT ALL ON database-name.* TO 'user-name'@'localhost' IDENTIFIED BY 'user-password'; -- Give permission to access your created DB.
use database-name;
source path/file.sql;
@chinmayrajyaguru
chinmayrajyaguru / example-import.sql
Created June 27, 2016 02:06
Import database from cPanel to MySQL through command line
CREATE DATABASE database-name DEFAULT CHARACTER SET utf8 COLLATE utf8_uni code_ci;
GRANT ALL ON database-name.* TO 'user-name'@'localhost' IDENTIFIED BY 'user-password';
use database-name;
source path/file.sql;