Skip to content

Instantly share code, notes, and snippets.

View gagimilicevic's full-sized avatar

Milicevic Dragan gagimilicevic

View GitHub Profile
@gagimilicevic
gagimilicevic / hide-editor.php
Created April 28, 2017 08:25 — forked from ramseyp/hide-editor.php
Hide the content editor for certain pages in WordPress
<?php
/**
* Hide editor on specific pages.
*
*/
add_action( 'admin_init', 'hide_editor' );
function hide_editor() {
// Get the Post ID.
@gagimilicevic
gagimilicevic / random-repeater.php
Created May 3, 2017 11:16 — forked from wesrice/random-repeater.php
Return a random row of data from an ACF repeater field
<?php
// Get the repeater field
$repeater = get_field( 'repeater_field_name' );
// Get a random rows. Change the second parameter in array_rand() to how many rows you want.
$random_rows = array_rand( $repeater, 2 );
// Loop through the random rows if more than one is returned
if( is_array( $random_rows ) ){
/**
* Add page selector to the customizer.
*
* @since Theme 1.0.0
*
* @param WP_Customize_Manager $wp_customize Customizer object.
*/
function prefix_customize_register( $wp_customize ) {
$wp_customize->add_section( 'showcase' , array(
@gagimilicevic
gagimilicevic / translate_woocommerce.php
Created July 20, 2017 13:53 — forked from dannyconnolly/translate_woocommerce.php
Change SKU text label in woocommerce to Product Code
function translate_woocommerce($translation, $text, $domain) {
if ($domain == 'woocommerce') {
switch ($text) {
case 'SKU':
$translation = 'Product Code';
break;
case 'SKU:':
$translation = 'Product Code:';
break;
@gagimilicevic
gagimilicevic / get-fisrt-paragraph.php
Created August 15, 2017 10:12 — forked from banago/get-fisrt-paragraph.php
Get first paragraph from a WordPress post.
<?php
/**
* Get first paragraph from a WordPress post. Use inside the Loop.
*
* @return string
*/
function get_first_paragraph(){
global $post;
$str = wpautop( get_the_content() );
@gagimilicevic
gagimilicevic / gist:9c4dac6ac6ef7cdbef49c60d0c0bb1f7
Created August 18, 2017 09:50 — forked from kloon/gist:2376300
WooCommerce Automatically add product to cart on site visit
/*
* goes in theme functions.php or a custom plugin
**/
// add item to cart on visit
add_action( 'template_redirect', 'add_product_to_cart' );
function add_product_to_cart() {
if ( ! is_admin() ) {
$product_id = 64;
$found = false;
//check if product already in cart
@gagimilicevic
gagimilicevic / gist:6082f633bdec20f5d3ef80ca64c6a50f
Created August 18, 2017 09:51 — forked from woogist/gist:5934881
Automatically add product to cart on visit depending on cart total value
/*
* goes in theme functions.php or a custom plugin
**/
// add item to cart on visit depending on cart total value
add_action( 'init', 'add_product_to_cart' );
function add_product_to_cart() {
if ( ! is_admin() ) {
global $woocommerce;
$product_id = 2831;
$found = false;
@gagimilicevic
gagimilicevic / paging.php
Created August 23, 2017 08:39 — forked from sloped/paging.php
Bootstrap Paging and Wordpress
<?php
//Use this function to create pagingation links that are styleable with Twitter Bootstrap
function paging() {
global $wp_query;
$total_pages = $wp_query->max_num_pages;
if ($total_pages > 1){
$current_page = max(1, get_query_var('paged'));