Skip to content

Instantly share code, notes, and snippets.

View marcosnakamine's full-sized avatar

Marcos Nakamine marcosnakamine

View GitHub Profile
<select name="id_estados" id="id_estados">
<option value="">UF</option>
<option value="AC">AC</option>
<option value="AL">AL</option>
<option value="AP">AP</option>
<option value="AM">AM</option>
<option value="BA">BA</option>
<option value="CE">CE</option>
<option value="DF">DF</option>
<option value="ES">ES</option>
@marcosnakamine
marcosnakamine / functions.php
Last active March 21, 2017 20:02
WordPress - Add new columns in dashboard
<?php
// REGISTER THE COLUMN
add_filter('manage_contatos_posts_columns', 'posts_columns');
function posts_columns($defaults){
unset($defaults['post_date']);
$defaults['email'] = 'E-mail';
return $defaults;
}
// RENDER THE COLUMN
@marcosnakamine
marcosnakamine / functions.php
Last active August 31, 2017 20:27
WordPress - Add new page in dashboard (iframe Google)
<?php
add_action('admin_menu','add_new_page');
function add_new_page(){
function add_new_page_content(){
include('inc-admin-new-page.php');
}
add_menu_page('New Page', 'New Page', 'publish_posts', 'new-page','add_new_page_content','');
}
// Google Presentation
@marcosnakamine
marcosnakamine / functions.php
Last active March 21, 2017 20:01
WordPress - Change login logo
<?php
add_action( 'login_head', 'custom_login_logo' );
function custom_login_logo() {
echo '
<style type="text/css">
h1 a { background-image: url('.get_template_directory_uri().'/img/new-logo.png) !important; }
</style>
';
}
@marcosnakamine
marcosnakamine / functions.php
Last active March 21, 2017 20:01
WordPress - Add widget content in Welcome dashboard
<?php
add_action('wp_dashboard_setup', 'add_dashboard_widgets' );
function add_dashboard_widgets() {
wp_add_dashboard_widget('dashboard_widget', 'Title', function($post, $callback_args){
echo 'Hello world';
});
}
@marcosnakamine
marcosnakamine / index.php
Last active March 21, 2017 20:01
WordPress - Add pagination
<?php
the_posts_pagination(array(
'mid_size' => 3,
'screen_reader_text' => ' '
));
@marcosnakamine
marcosnakamine / functions.php
Last active March 21, 2017 20:01
WordPress - Add new post type
<?php
add_action('init','register_new_post_type');
function register_new_post_type(){
$args = array(
'label' => 'New Type',
'show_ui' => true,
'supports' => array( 'title', 'editor', 'thumbnail' ),
'public' => true,
'hierarchical' => true,
'has_archive' => true
@marcosnakamine
marcosnakamine / functions.php
Last active March 21, 2017 20:02
WordPress - Add dynamic sidebar
<?php
add_action( 'init', 'theme_widgets_init' );
function theme_widgets_init() {
register_sidebar( array (
'name' => 'Widget',
'id' => 'primary_widget_area',
'before_widget' => '<div id="%1$s" class="widget-container %2$s">',
'after_widget' => "</div>",
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
@marcosnakamine
marcosnakamine / index.php
Last active March 21, 2017 20:02
WordPress - Get source of image gallery by post id
<?php
function get_image_gallery_src( $post_id ) {
$gallery = get_post_gallery( $post_id, false );
$gallery_id = explode( ',', $gallery['ids'] );
$result = array();
foreach ( $gallery_id as $key => $value ) {
$img = wp_get_attachment_image_src( $value, 'full' );
array_push( $result, array(
'title' => get_the_title( $value ),
'src' => $img[0]
@marcosnakamine
marcosnakamine / functions.php
Last active March 21, 2017 20:02
WordPress - Add theme supports
<?php
add_action( 'after_setup_theme', 'add_theme_supports' );
function add_theme_supports() {
add_theme_support( 'title-tag' );
add_theme_support( 'post-thumbnails' );
add_theme_support( 'html5' );
add_theme_support( 'custom-logo' );
add_theme_support( 'woocommerce' );
}