Skip to content

Instantly share code, notes, and snippets.

@giventofly
giventofly / acf-menu.php
Created April 22, 2018 15:32
ACF Menu example
if( function_exists('acf_add_options_page') ) {
//acf_add_options_page('More Theme Settings');
acf_add_options_page(array(
'page_title' => 'Configurar Site',
'menu_title' => 'Configurar Site',
'menu_slug' => 'general-settings',
'capability' => 'edit_posts',
/* redirect para 1fst child*/
//scroll FAQ
document.addEventListener('DOMContentLoaded', function () {
document.querySelector('.meta-about-content-left[data-section=faq]').addEventListener('click', function (e) {
e.preventDefault();
//get id to jump
const itemlink = $(e.target);
if (itemlink.is("a")) {
let value = itemlink.attr('href');
let jump;
@giventofly
giventofly / wordpress-snippet-allow-files-uploaddir.php
Created May 4, 2018 13:51
Wordpress upload to custom folder and allow different extensions
//uploads to specific dir
//allow xml and .wer
$allowedExtensions = array('wer' => 'application/wer', 'xml' => 'application/xml');
$pathinsideuploads = '/myfiles';
add_filter('upload_mimes', 'custom_upload_files');
function custom_upload_files($mimes) {
global $allowedExtensions;
$mimes = array_merge($mimes, $allowedExtensions);
return $mimes;
@giventofly
giventofly / wp-admin-menu-ajax-request
Created May 4, 2018 14:44
wordpress add admin menu item post ajax request on button press
//add a menu page with a button to do stuff
add_action('admin_menu', 'my_menu_pages');
function my_menu_pages(){
add_menu_page('Actualizar Liga Magus', 'Actualizar Liga', 'manage_options', 'my-menu', 'my_menu_output','',0 );
}
function my_menu_output(){
$html = '<a href="#ajaxthing" class="myajax">Teste</a>';
echo $html;
}
add_action('admin_head', 'my_action_javascript');
@giventofly
giventofly / randomColor.js
Created May 8, 2018 16:37
randomColor hexadecimal
function getRandomColor() {
let letters = '0123456789ABCDEF';
let color = '#';
for (let i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
@giventofly
giventofly / acf-load-select-field-from-another-field.php
Created May 9, 2018 11:40
ACF load values to select field from another field
//check select field from .json
add_filter('acf/load_field/key=field_5af2cece02f00', function( $field ){
// options of the choices to add to select
$field['choices'] = array();
// dynamic data we want to popuplate with
$bundles = get_field('gerir_marcas', 'option' );
//$portfolio = get_field('item_portfolio','option');
//var_dump($bundles);
@giventofly
giventofly / menu-functions.php
Last active May 10, 2018 14:16
wordpress add menu
function register_my_menus() {
register_nav_menus(
array(
'footer-menu' => __( 'Footer Menu' ), //footer menu
'extra-menu' => __( 'Extra Menu' ) //extra
)
);
}
add_action( 'init', 'register_my_menus' );
@giventofly
giventofly / wpml-wp-custom-link.php
Last active May 15, 2018 09:24
WPML wordpress custom menu links
@giventofly
giventofly / remover duplicados vanillajs.js
Created May 17, 2018 15:02
remover duplicados vanilla js
//https://codehandbook.org/how-to-remove-duplicates-from-javascript-array/
//remover duplicados
function removeDuplicates(arr) {
let unique_array = []
for (let i = 0; i < arr.length; i++) {
if (unique_array.indexOf(arr[i]) == -1) {
unique_array.push(arr[i])
}
}
@giventofly
giventofly / image css lightbox effect.html
Created May 21, 2018 08:55
simple CSS lightbox effect
<!-- //original: https://codepen.io/gschier/pen/HCoqh -->
<!-- thumbnail image wrapped in a link -->
<a href="#img1">
<img src="http://insomnia.rest/images/screens/main.png" class="thumbnail">
</a>
<a href="#img2">
<img src="http://via.placeholder.com/1350x1150" class="thumbnail">
</a>