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
@dingo-d
dingo-d / functions.php
Created April 3, 2016 18:56
A code to make excerpts meta box show above the post content
<?php
add_action( 'admin_menu' , 'mytheme_remove_normal_excerpt' );
if (!function_exists('mytheme_remove_normal_excerpt')) {
function mytheme_remove_normal_excerpt() {
remove_meta_box( 'postexcerpt' , 'post' , 'normal' );
}
}
@dingo-d
dingo-d / is_admin.php
Created April 3, 2016 19:08
A code that will make sure you enqueue your custom scripts only on pages you need.
<?php
if ( !function_exists('mytheme_is_admin_page') ) {
function mytheme_is_admin_page($new_edit = null){
global $pagenow;
if (!is_admin()) return false;
if($new_edit == "edit") { // if is edit post page
return in_array( $pagenow, array( 'post.php', ) );
@dingo-d
dingo-d / development.php
Last active May 3, 2016 10:43
Code to find out what's in the post form of the wordpress using AJAX - development purposes only
<?php
add_action( 'wp_ajax_my_action', 'my_action_callback' );
function my_action_callback() {
wp_die(print_r($_POST));
}
add_action( 'post_submitbox_misc_actions', 'post_ajax' );
@dingo-d
dingo-d / onload-fix.js
Created May 13, 2016 08:55
A solution to $(window).on('load', function(){}); issue in iOS, in Safari for videos and audios. If you embed the video or audio that has preload="none" set, Safari will regard this like the page didn't finish loadin, so the code inside the on.load event will never fire. This is a temporary fix for this issue.
var iOS8 = navigator.userAgent.match(/(iPad|iPhone|iPod).*OS 8_\d/i);
if( iOS8 ){
setTimeout(function(){
$(window).trigger('load');
}, 3500);
}
@dingo-d
dingo-d / functions.php
Created May 23, 2016 07:28
Adding google fonts to WordPress
<?php
add_action( 'wp_enqueue_scripts', 'yourtheme_frontend_scripts');
/********* Frontend Scripts ***********/
if ( ! function_exists( 'yourtheme_frontend_scripts' ) ){
function yourtheme_frontend_scripts() {
wp_enqueue_style('yourtheme_google_fonts', yourtheme_fonts_url(), array(), null);
}
}
@dingo-d
dingo-d / limit_upload.php
Last active June 1, 2016 13:38
Limit file upload size in WordPress - put as a separate file or in functions.php
<?php
/**
* Limit file upload size
*
* For more info about file upload variables check: http://php.net/manual/en/reserved.variables.files.php
* For all mime types you can check http://www.freeformatter.com/mime-types-list.html
*
* @param string $file File for upload
*/
@dingo-d
dingo-d / divisible_number.php
Last active June 10, 2016 08:16
A simple php function that checks for the number of divisions and the resulting remainder.
<?php
function divisible_times($number, $divider) {
$count = 0;
$remainder = $number % $divider;
$num_array = range($number, 1);
foreach($num_array as $num) {
if($num % $divider == 0){
$count++;
}
@dingo-d
dingo-d / knowledgebase-cpt.php
Created July 4, 2016 06:36
A custom post type (CPT) called knowledgebase with the added taxonomy, and additional field called 'Category order'. Can be modified further to accommodate additional fields in the taxonomy, add metaboxes to CPT etc.
<?php
/**
* Custom post type and taxonomy registration
*
* @since 1.0.0
*/
add_action('init', 'knowledgebase_register_type');
@dingo-d
dingo-d / content_in_cat.php
Created July 14, 2016 16:49
Adding content you've created as a separate page anywhere in your templates or main WordPress files...
<?php
$content_after_category = get_theme_mod('content_after_category', false); // in Customizer set this as dropdown pages control
if($content_after_category){
$page_id = get_page($content_after_category);
echo apply_filters('the_content', $page_id->post_content);
}
?>
@dingo-d
dingo-d / menu_walker.php
Last active July 30, 2016 21:11
Menu walker with sidebars in the menu option, and megamenu. Goes with [megamenu_admin.js](https://gist.github.com/dingo-d/d917ddebd65be700fbcb) file for toggling the megamenu option in the menus
<?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 ) ) {
if ( 'nav_menu_item' == $menu_item->post_type ) {
$menu_item->description = apply_filters( 'nav_menu_description', $menu_item->post_content );
}
}