Skip to content

Instantly share code, notes, and snippets.

View kosinix's full-sized avatar

Kosinix kosinix

  • Philippines
View GitHub Profile
@kosinix
kosinix / header.php
Last active October 11, 2021 08:43
WordPress basic CSS for styling nav menus with wp_page_menu taken into account. Supports sub-menus as dropdowns.
<?php
// Somewhere in your header.php add this. container_class and menu_class should match the CSS main class.
wp_nav_menu( array( 'theme_location' => 'primary', 'container_class' => 'nav-menu', 'menu_class' => 'nav-menu' ) );
@kosinix
kosinix / get-x-y.js
Created December 29, 2013 08:01
Jquery get element x and y position on screen
$('body').on('click', 'a', function(e){
$(this).offset().left; // x
$(this).offset().top; // y
});
@kosinix
kosinix / gist:8267252
Last active November 19, 2021 02:04
Prevent Access to Subdomain Folder from Main Domain. Note: Place this in your sub domain's .htaccess file (public_html/subdomain). Change subdomain to actual sub-domain and mysite.com to your main domain.
RedirectMatch ^/subdomain/(.*)$ http://subdomain.mysite.com/$1
@kosinix
kosinix / active-element.js
Last active January 2, 2016 08:58
jQuery - Getting the currently focused element. Useful when debugging keyboard events on focused elements
jQuery(document).on('click', 'body', function( event ) {
console.log(document.activeElement);
});
@kosinix
kosinix / index.html
Created January 6, 2014 07:58
Keyboard Experiment - Detecting keys in javascript. Live demo: http://jsfiddle.net/rsyz5xn6/
<!doctype html>
<html lang="en">
<head>
<title>Keyboard Experiments</title>
<script type="text/javascript" src="keyboard.js"></script>
</head>
<body>
Press either left or right arrow keys
</body>
@kosinix
kosinix / tpl.php
Created January 30, 2014 11:42
Learn what template you are in WordPress
<?php
function template_hierarchy_detector(){
$out = array();
if ( is_404() ) {
$out[] = 'Error 404 Page';
}
if( is_search() ){
$out[] = 'Search Result Page';
}
if( is_archive() ){
<?php
function get_pages_tree($parent_id=0){
$args = array(
'parent'=>$parent_id
);
$pages = get_pages( $args );
if($pages){
@kosinix
kosinix / get_pages_flattened_tree.php
Created February 3, 2014 11:12
Wordpress flat list
<?php
function get_pages_flattened_tree(&$flattened_list, $parent_id=0, $level=0){
$args = array(
'parent'=>$parent_id
);
$pages = get_pages( $args );
if($pages){
@kosinix
kosinix / gist:7d8f19352782ff598e1f
Created August 20, 2014 00:04
Disable Post Revision and Delay Autosave in WP
wp-config.php:
define('AUTOSAVE_INTERVAL', 300 ); // seconds
define('WP_POST_REVISIONS', false );
SQL:
DELETE FROM wp_posts WHERE post_type = "revision";
@kosinix
kosinix / gist:993b09fbb3389e44391b
Created September 4, 2014 05:49
C# - Delete a folder in a zip using dotnetzip. Docs: http://dotnetzip.herobo.com/DNZHelp/Index.html
using (ZipFile zip = ZipFile.Read(@"D:\path\to\ZipFile.zip"))
{
zip.RemoveSelectedEntries("foldername/*"); // Remove folder and all its contents
zip.Save();
}