Skip to content

Instantly share code, notes, and snippets.

View yoren's full-sized avatar

Yoren Chang yoren

View GitHub Profile
@yoren
yoren / gist:4737280
Last active December 12, 2015 07:28
WordPress: Change “Enter Title Here” placeholder
<?php
/**
* @link http://www.wpexplorer.com/useful-wordpress-snippets/
*/
function change_default_title( $title ){
$screen = get_current_screen();
if ( '_your_custom_post_type_' == $screen->post_type ) {
@yoren
yoren / gist:4737296
Created February 8, 2013 07:33
WordPress: use Jetpack’s ShareDaddy plugin without connecting to WordPress.com
<?php
/**
* @link http://wpgarage.com/plugins/how-to-use-jetpacks-sharedaddy-without-connecting-to-wordpress-com/
* Modify plugin file - jetpack-sharedaddy.php
* /
function hack_jetpack_offline_mode() {
if ( ! file_exists( WP_PLUGIN_DIR . '/jetpack/' ) || class_exists( 'Jetpack' ) )
return;
require_once( WP_PLUGIN_DIR . '/jetpack/jetpack.php' );
@yoren
yoren / gist:5194306
Created March 19, 2013 07:24
WordPress: Change wordpress posts to news
<?php
/**
* Change wordpress posts to news
*
* @link http://new2wp.com/snippet/change-wordpress-posts-post-type-news/
*/
function change_post_menu_label() {
global $menu;
global $submenu;
@yoren
yoren / gist:5234827
Last active December 15, 2015 08:59
WordPress: Add link button to export posts into a Excel file
jQuery(document).ready(function($) {
if(typeof(pagenow) !== 'undefined' && pagenow == 'edit-post') {
$('h2 .add-new-h2').after('<a id="data_output" class="add-new-h2" href="?ay_output=excel" target="_blank">輸出 Excel 會員列表</a>');
}
});
@yoren
yoren / gist:5234955
Created March 25, 2013 04:36
WordPress: Post type capabilities
<?php
$args = array(
'labels' => array(
'name' => '服務中心',
'signular_name' => '服務中心'
),
'public' => true,
'hierarchical' => true,
'supports' => array(
'title', 'editor', 'page-attributes'
@yoren
yoren / functions.php
Created May 16, 2013 13:30
WordPress: Custom Media Size Dropdown
// Set the new image sizes
if(function_exists( 'add_image_size')){
add_image_size('blog-large', 900, 700, false);
}
// Tell the media panel to add the new size to the dropbown
function custom_image_sizes($sizes) {
$addsizes = array(
"blog-large" => __("X-Large")
);
@yoren
yoren / index.html
Created October 24, 2013 17:11 — forked from anonymous/index.html
A quick demo showing how to capture the order of connected sortable lists.
<ul id="image-list1" class="sortable-list">
<li id="a">A</li>
<li id="b">B</li>
<li id="c">C</li>
</ul>
<ul id="image-list2" class="sortable-list">
<li id="1">1</li>
<li id="2">2</li>
<li id="3">3</li>
<?php
function copy_post_to_blog($post_id, $target_blog_id) {
$post = get_post($post_id, ARRAY_A); // get the original post
$meta = get_post_meta($post_id);
$post['ID'] = ''; // empty id field, to tell wordpress that this will be a new post
switch_to_blog($target_blog_id); // switch to target blog
$inserted_post_id = wp_insert_post($post); // insert the post
foreach($meta as $key=>$value) {
update_post_meta($inserted_post_id,$key,$value[0]);
}
@yoren
yoren / functions.php
Last active January 1, 2016 08:39 — forked from WerdsWords/post_row_actions.php
Remove quickedit.
<?php
/**
* Disable Quick Edit row action for posts
*
* @see WP_Posts_List_Table::single_row()
*
* @param array $actions An array of row actions, keys corresponding to the span class attribute of each element.
* @param object $post The post object.
*
* @return array The row actions array.
@yoren
yoren / functions.php
Created January 10, 2014 02:33
WordPress: Skip dashboard when log into backend.
<?php
/**
* Skip dashboard when log into backend.
*/
function my_login_redirect( $redirect_to, $url, $user ) {
if ( ! is_wp_error( $user ) && user_can( $user, 'edit_posts' ) ) {
$redirect_to = admin_url( 'edit.php' );
}