Skip to content

Instantly share code, notes, and snippets.

View leowebguy's full-sized avatar

Leo Leoncio leowebguy

View GitHub Profile
@leowebguy
leowebguy / functions.php
Last active December 15, 2015 15:08
WordPress register custom Widget
function custom_widget_init() {
register_sidebar( array(
'name' => 'Featured + Search',
'id' => 'featured_search1',
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<h2 class="featured_search1">',
'after_title' => '</h2>',
) );
register_sidebar( array(
@leowebguy
leowebguy / functions.php
Created December 14, 2015 13:46
Add content to WordPress using wp_head if is Front Page
function add_scroll() {
if ( is_page( 'Home' ) ) {
echo '<div class="slide_anchor_holder active"><a class="slide_anchor_button anchor current" href="#scroll-down">See What Makes Us Different</a></div>';
echo '<div class="slide_anchor_line"><span class="slide_anchor_line1"></span></div>';
echo '<div class="latest_news"><a class="slide_anchor_button anchor current" href="#scroll-news">View Our Latest News</a></div>';
}
}
add_action('wp_head', 'add_scroll' );
@leowebguy
leowebguy / wp-config.php
Created November 24, 2015 20:41
WordPress wp-config.php best practices setup.
<?php
/**
* The base configurations of the WordPress bla bla bla...
*/
define('DB_NAME', 'project1_db');
define('DB_USER', 'project1_usr1');
define('DB_PASSWORD', 'db-password-here');
define('DB_HOST', 'localhost');
@leowebguy
leowebguy / cron-job-backup.sh
Last active November 24, 2015 02:23
Simplified bash code to execute database and files backup using CPanel Cron Job
#!/bin/bash
PATH=/usr/sbin:/sbin:/bin:/usr/bin
now="$(date +"%Y-%m-%d-%H%M")"
# backup root_db1 mysql database
mysqldump -u root_usr1 -h localhost -p'your-password' root_db1 | gzip -f > ./public_html/_backups/db1-$now.sql.gz &&
# backup site1/wp-content (wordpress content folder) and exclude .sass-cache folder (Cannot open: Permission denied)
@leowebguy
leowebguy / functions.php
Created November 19, 2015 21:06
Check WordPress user and add Admin Styles
<?php
global $current_user;
get_currentuserinfo();
function inject_admin_styles() {
echo '<style type="text/css">#menu-posts {display:none;} </style>';
}
if ($current_user->user_login !== 'admin') { //replace this with your admin user
@leowebguy
leowebguy / scripts.js
Created November 16, 2015 21:18
Get alt attribute and append title to the same element (jquery)
$(document).ready(function($){
$(".wpb_image").each(function() {
var title = $(this).find('img').attr('alt');
$(this).append('<div class="wpb_image_title"><h4>'+title+'</h4></div>');
});
});
@leowebguy
leowebguy / query.php
Created November 16, 2015 21:15
Insert data into custom table on WordPress (wpdb)
<?php
global $wpdb;
$value = preg_replace("/\r\n|\r|\n/",'-',$value); //replace breaks by "-"
$sql = "INSERT INTO `".$wpdb->prefix."contacts` (`CONTENT`) values ('" . $value . "|WEBDEV|" . date("m.d.y h.i A") . "')";
$wpdb->query($sql);
@leowebguy
leowebguy / robots.txt
Last active November 16, 2015 21:09
Robots TXT for WordPress (robots.txt)
User-agent: *
Allow: /
Disallow: /cgi-bin
Disallow: /wp-admin
Disallow: /wp-includes
Disallow: /wp-content
Disallow: /xmlrpc.php
Allow: /wp-content/uploads/
User-agent: Mediapartners-Google
@leowebguy
leowebguy / functions.php
Last active December 14, 2015 13:48
Quick integrate lightbox to WordPress
<?php
/****
* Download lighbox js on http://lokeshdhakar.com/projects/lightbox/
* Upload to your server Ex. /public_html/lightbox/
*****/
function enqueue_lightbox() {
wp_register_style( 'lightboxcss', get_stylesheet_directory_uri() . '/lightbox/css/lightbox.css' );
wp_register_script('lightbox', get_stylesheet_directory_uri() . '/lightbox/js/lightbox.js','','',TRUE);
@leowebguy
leowebguy / functions.php
Last active November 17, 2015 02:50
Custom shortcode for Visual Composer on WordPress
<?php
function vc_integrate_custom() {
vc_map( array (
"name" => "Team",
"base" => "team",
"category" => 'Custom',
"icon" => "icon-wpb-team",
"allowed_container_element" => 'vc_row',
"params" => array(