Skip to content

Instantly share code, notes, and snippets.

View marcosnakamine's full-sized avatar

Marcos Nakamine marcosnakamine

View GitHub Profile
@marcosnakamine
marcosnakamine / functions.php
Last active March 21, 2017 20:02
WordPress - Add style with wp_enqueue_style
<?php
add_action('wp_enqueue_scripts', 'enqueue_scripts');
function enqueue_scripts() {
wp_enqueue_style( 'main', get_template_directory_uri().'/style.css' );
}
@marcosnakamine
marcosnakamine / index.php
Last active March 21, 2017 20:02
WordPress - Insert new post
<?php
$post_id = wp_insert_post( array(
'post_content' => 'Content',
'post_title' => 'Title',
'post_type' => 'custom_post_type',
'tax_input' => array( 'taxonomy_post_type' )
) );
wp_set_object_terms( $post_id, 'custom_taxonomy', 'taxonomy_post_type', true );
@marcosnakamine
marcosnakamine / functions.php
Last active March 21, 2017 20:02
WordPress - Remove editor support of specific page by title
<?php
add_action( 'admin_init', 'hide_editor' );
function hide_editor() {
$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
if( !isset( $post_id ) ) return;
if( get_the_title( $post_id ) == 'Home' ){
remove_post_type_support( 'page', 'editor' );
}
}
@marcosnakamine
marcosnakamine / script.js
Created November 25, 2016 23:36
Fancybox - Trigger open image
$.fancybox.open({
href:'image.jpg'
});
@marcosnakamine
marcosnakamine / date.php
Created November 27, 2016 16:35
PHP - Compare two dates
<?php
if(strtotime(date('d-m-Y')) > strtotime('27-11-2016')) {
echo 'OK';
}
@marcosnakamine
marcosnakamine / index.php
Last active March 21, 2017 20:02
WordPress - Get src of post galery
<?php
$aFotos = get_post_gallery(get_the_ID(), false);
$aFotosId = explode(',',$aFotos['ids']);
$aFotos = $aFotos['src'];
foreach ($aFotosId as $key => $value) {
echo $aFotos[$key];
}
@marcosnakamine
marcosnakamine / 000-default.conf
Last active January 24, 2017 16:24
Apache 2.4 - Localhost configuration
#/etc/apache2/sites-available/000-default.conf
DocumentRoot /home/user/Projects
<Directory /home/user/Projects/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
Require all granted
</Directory>
@marcosnakamine
marcosnakamine / index.php
Last active March 21, 2017 20:04
WooCommerce - Get product info
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
<style>
img {max-width:100%; }
</style>
</head>
<body>
@marcosnakamine
marcosnakamine / functions.php
Last active April 22, 2024 13:52
WooCommerce - Add new rule to ACF
<?php
add_filter('acf/location/rule_types', 'acf_location_rules_types');
function acf_location_rules_types( $choices ) {
$choices['Woocommerce']['woocommerce_attribute'] = 'Atributo';
return $choices;
}
add_filter('acf/location/rule_values/woocommerce_attribute', 'acf_location_rules_values_woocommerce_attribute');
function acf_location_rules_values_woocommerce_attribute( $choices ) {
$atributes = wc_get_attribute_taxonomies();
@marcosnakamine
marcosnakamine / index.php
Last active March 21, 2017 20:03
WordPress - Conditional tags
<?php
var_dump('is_shop '.is_shop());
var_dump('is_product '.is_product());
var_dump('is_single '.is_single());
var_dump('is_archive '.is_archive());
var_dump('is_page '.is_page());
var_dump('is_product_category '.is_product_category());
var_dump('is_woocommerce '.is_woocommerce());