Skip to content

Instantly share code, notes, and snippets.

View dingo-d's full-sized avatar
🏠
Working from home

Denis Žoljom dingo-d

🏠
Working from home
View GitHub Profile
<?php
/**
* !!WARNING!!
* This script will delete everything you have in wordpress.
* I use it only when developing something that requires me to delete everything, e.g. importer.
* You can comment some parts out if you need to quickly delete just posts, or pages or so, but still be very careful!!!
*
* @author Denis Žoljom (https://github.com/dingo-d)
* @license Free to use at your own risk
@dingo-d
dingo-d / pagination.php
Last active December 26, 2015 08:20
Custom made pagination for wordpress
<?php
global $wp_query;
$total_pages = $wp_query->max_num_pages;
if ($total_pages > 1){
$current_page = max(1, get_query_var('paged'));
$permalink_structure = get_option('permalink_structure');
$format = empty( $permalink_structure ) ? '?paged=%#%' : 'page/%#%/';
echo '
<section id="pagination" class="clearfix">
<div class="container">
@dingo-d
dingo-d / add-pages-post-metabox.php
Last active February 14, 2016 20:38
A gist based on repeater fields as seen https://gist.github.com/da1nonly/2057532 by da1nonly with added wordpress post link ability using wpLink by modifying this answer http://wordpress.stackexchange.com/questions/127088/how-can-i-use-the-built-in-wordpress-browse-link-functionality/135843#135843
<?php
add_action('admin_init', 'add_meta_boxes', 1);
function add_meta_boxes() {
add_meta_box( 'repeatable-fields', esc_html__('Related Articles', 'mytheme'), 'my_related_articles_meta_box_display', 'post', 'normal', 'high');
}
function my_related_articles_meta_box_display() {
@dingo-d
dingo-d / menu-walker.php
Last active January 19, 2016 17:27
A menu walker for adding sidebars in menu. The megamenu needs to be handled by javascript (or in any other way)
<?php
// Allow HTML descriptions in WordPress Menu
remove_filter( 'nav_menu_description', 'strip_tags' );
function my_plugin_wp_setup_nav_menu_item( $menu_item ) {
if ( isset( $menu_item->post_type ) && 'nav_menu_item' == $menu_item->post_type) {
$menu_item->description = apply_filters( 'nav_menu_description', $menu_item->post_content );
}
@dingo-d
dingo-d / header_layout.php
Created January 20, 2016 12:48
A header layout with AJAX login and register forms (buttons) a part of Header AJAX login/register gist (1)
<header id="main_header" class="clearfix">
<div class="top_bar">
<div class="container">
<div class="ajax_login">
<form id="login" action="login" method="post">
<h1><?php esc_attr_e('User login','yourtheme') ?></h1>
<p class="status"></p>
<input id="username" type="text" name="username" placeholder="<?php esc_attr_e('Username','yourtheme') ?>">
<input id="password" type="password" name="password" placeholder="<?php esc_attr_e('Password','yourtheme') ?>">
<div class="forgotten_box">
@dingo-d
dingo-d / functions.php
Last active January 20, 2016 13:35
A part of the functions.php file that is used to log in or register user via AJAX. Part of Header AJAX login/register gist (2)
<?php
/********* AJAX Login ***********/
function yourtheme_ajax_login_init(){
wp_register_script('ajax-login-script', get_template_directory_uri() . '/js/ajax-login-script.js', array('jquery') );
wp_enqueue_script('ajax-login-script');
wp_localize_script( 'ajax-login-script', 'ajax_login_object', array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
@dingo-d
dingo-d / ajax-login-script.js
Last active January 20, 2016 14:43
A javascript file that handles AJAX calls and on click events for AJAX log in and register. Part of Header AJAX login/register gist (3)
jQuery(document).ready(function($) {
"use strict";
// Show the login dialog box on click
$('a#show_login').on('click', function(e){
$('.ajax_login_overlay').fadeIn(500);
$('form#login').fadeIn(500);
e.preventDefault();
});
@dingo-d
dingo-d / ajax-login.css
Last active January 20, 2016 12:56
Unfinished .css file for AJAX log in and register. Part of Header AJAX login/register gist (4)
/*------------------------ AJAX login -------------------------*/
.top_bar{
text-align: right;
}
.top_bar .ajax_login{
display: inline-block;
margin-right: 10px;
}
@dingo-d
dingo-d / custom-registration-forms.php
Created January 20, 2016 13:35
Custom registration forms
/********* Custom Registration Form ***********/
add_action( 'register_form', 'travelnews_register_form' );
if (!function_exists('travelnews_register_form')) {
function travelnews_register_form() {
$first_name = ( ! empty( $_POST['first_name'] ) ) ? trim( $_POST['first_name'] ) : '';
$last_name = ( ! empty( $_POST['last_name'] ) ) ? trim( $_POST['last_name'] ) : '';
@dingo-d
dingo-d / post_order_customizer.php
Created February 11, 2016 07:55
A code to put in your customizer.php and in your functions.php of the wordpress to order your home and category posts
<?php
/**
The below code goes in customizer.php of your theme
**/
/**
------------------------------------------------------------
SECTION: Post order on home page and index pages
------------------------------------------------------------