Add delivery date and time for woocommerce

/** * Add the field to the checkout * */ add_action(‘woocommerce_after_checkout_billing_form’, ‘my_custom_checkout_field’); function my_custom_checkout_field($checkout) { echo ” . __(‘Prefered delivery time’, ‘woothemes’) . ”; $tomorrow = date(‘Y-m-d’, strtotime(the_date(‘Y-m-d’, ”,”, FALSE) …

Add Custom Post Type Columns for wordpress

这儿以 costom post portfolio 为例, 为 portfolio 列表页加上 两个分类列。删除时间列。 add_filter( ‘manage_edit-portfolio_columns’, ‘set_custom_edit_portfolio_columns’ ); add_action( ‘manage_portfolio_posts_custom_column’ , ‘custom_portfolio_column’, 10, 2 ); function set_custom_edit_portfolio_columns($columns) { unset($columns[‘date’]); //注销不需要的列 return $columns + array(‘portfolio_category’ => …

icl_link_to_element and icl_object_id

Example usage Example Purpose Produced HTML <?php icl_link_to_element(10); ?> Link to page 10 (support page) <a href=”/support/”>Support</a> <?php icl_link_to_element(10,’post’,__(‘Get help’)); ?> Link to support page with an alternative link text …

修改WordPress里用户页的联系信息(Contact Info)

新旧界面对比,旧界面中的 aim,jabber,yim 被去掉了,加入了时下大家最熟悉的 facebook,twitter …… add_filter( ‘user_contactmethods’ , ‘update_contact_methods’ , 10 , 1 ); function update_contact_methods( $contactmethods ) { // Add new fields $contactmethods[‘phone’] = ‘Phone’; $contactmethods[‘mobile’] = ‘Mobile’; $contactmethods[‘address’] …

WPML Coding API and Custom Language Switcher

老是打不开这些页面,干脆复制到自己的地盘来了。方便自己也方便大家。 神马?WPML 是啥,自己百度吧! WPML offers functions that can be used in your WordPress theme to provide correct support for multilingual themes. Function Purpose Notes do_action(‘icl_language_selector’) Insert the drop down language …

WordPress debug code

WordPress debug 代码,把它放在function 文件里,就会在每页的页脚出现这个,包括当前模板,重写规则,Query 等等。 add_action( ‘template_include’, ‘_childtheme_print_template_name’ ); function _childtheme_print_template_name( $template_name ) { global $childtheme_template_name; $childtheme_template_name = $template_name; add_action( ‘wp_footer’, ‘childtheme_print_template_name’, 100 ); return $template_name; } function childtheme_print_template_name( ) …

Contact Form 7 的那些事儿

Customization of Contact Form 7 plugin Additional headers:You can input any header lines into the field and you can insert any tags into any place in each header line, just …

WordPress Portfolio work with Isotope and Infinite Scroll

准备:需要的jQuery插件 Isotope: 神奇的布局精致的jQuery插件。演示 Infinite Scroll:无限滚动被称为autopagerize的,unpaginate,无尽的网页。但实质上,它是预取从随后出现的页面上的内容,并直接将其添加到用户的当前页面。http://www.infinite-scroll.com/ 演示 新建文章类型 portfolio 和 Portfolio 分类  function my_post_types() { register_post_type(‘portfolio’, array( ‘label’ => __(‘Portfolio’,’itc’), ‘singular_label’ => __(‘Portfolio’, ‘itc’), ‘_builtin’ => false, //’exclude_from_search’ => false, // Exclude from Search …

Get Featured Image with timthumb

$w = ‘350’; $h = ‘200’; if (has_post_thumbnail()) { $large_image_url = wp_get_attachment_image_src(get_post_thumbnail_id(), ‘full’); echo ”; } else { echo ”; }

Create wordpress custom widget

代码放到 functions.php 就可以在小工具里获得该 widget。 class weibo_widget extends WP_Widget { public function __construct() { // widget actual processes //get_popular_resource parent::__construct( ‘weibo_widget’, // Base ID ‘Weibo widget’, // Name array(‘description’ => __(‘Weibo …

Media, Audio, Video Player for wordpress

function yyy_html5_audio($url) { if (preg_match(‘/Firefox/’, $_SERVER[“HTTP_USER_AGENT”])) { // For religious reasons Firefox does not support MP3 format in HTML5 audio tag, use Flash player instead $embed = ”; } else …

让Qtranslate 支持 Custom Taxonomy

If you wanted to automatically detect taxonomies, and then add translation edit fields here is some code: 如果你想要自动探测 Custom Taxonomy,然后给他们加上翻译字段, 把这段代码放在主题的 function.php 里。 function qtranslate_edit_taxonomies(){ $args=array( ‘public’ => true , ‘_builtin’ …

去除 wordpress 链接中的域名

上次说到去除一些不必需的 class 和 ID, 从上图看出,这些 domain name 似乎也是不必须的,如果像下图: 这样会不会更好呢,下面的代码可以实现这个效果。 add_filter(‘walker_nav_menu_start_el’ , ‘yao_walker_nav_menu_start_el’ , 10 , 2); function yao_walker_nav_menu_start_el($item_output, $item){ //print_r($item); $home_url = home_url(); $site_url = site_url(); preg_match(“/^(http:\/\/)?([^\/]+)/i”,site_url(), $matches); $domain = …

清理wordpress菜单里的 id 和 class

wordpress 默认的菜单会产生很多 id 和 class 在代码里,打多时候,这些都是不需要的。 通过下面2个滤镜,可以去除那些我们不需要的 class 和 ID add_filter(‘nav_menu_css_class’ , ‘special_nav_class’ , 10 , 2); function special_nav_class($classes, $item){ $current_and_home = array(“current-menu-item”, “menu-item-home”, ‘last’); $classes = array_intersect($item->classes,$current_and_home); //保留有需要的 class …

WordPress 只显示当前用户的文章

当Wordpress在一个多用户的贡献者列表管理页面后,他可以看到不仅是他的文章,但也从其他捐助者的文章。即使他不能编辑其他职位,这仍可能是一个问题,如果有很多文章已经和他有搜索一页一页地找到他的文章。如何只显示他自己的文章?这段代码会显示如何做到这一点。 function mypo_parse_query_useronly( $wp_query ) { if ( strpos( $_SERVER[ ‘REQUEST_URI’ ], ‘/wp-admin/edit.php’ ) !== false ) { if ( !current_user_can( ‘level_10’ ) ) { global $current_user; $wp_query->set( ‘author’, $current_user->id …