25
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

WordPress Bogo をカスタム投稿タイプでも使う

Last updated at Posted at 2017-06-07

Bogo とは

WordPressで多言語サイト運用するならこのプラグインが便利。
カスタム投稿タイプでも使うにはちょっとしたカスタマイズが必要

コード

プラグインで bogo_localizable_post_types というフィルターフックが用意されてるのでそれを使えばOK。
$localizable に投稿タイプ名が配列で入るので、加える。

my_localizable_post_types1.php
<?php
/**
 * Support custom post type with bogo.
 *
 * @param array $localizable Supported post types.
 * @return array
 */
function my_localizable_post_types( $localizable ) {
	$localizable[] = 'custom_post_type_name';
	return $localizable;
}
add_filter( 'bogo_localizable_post_types', 'my_localizable_post_types', 10, 1 );

複数のカスタム投稿タイプを追加する場合は $localizable[] = 'custom_post_type_name'; の複数行記述すればよいが、いちいち投稿タイプを書くのは面倒という場合は get_post_types() 使えばよい。
https://developer.wordpress.org/reference/functions/get_post_types/

例は public なカスタム投稿タイプを全て追加するコード。

my_localizable_post_types2.php
<?php
/**
 * Support custom post type with bogo.
 *
 * @param array $localizable Supported post types.
 * @return array
 */
function my_localizable_post_types( $localizable ) {
	$args = array(
		'public'   => true,
		'_builtin' => false
	);
	$custom_post_types = get_post_types( $args );
	return array_merge( $localizable, $custom_post_types );
}
add_filter( 'bogo_localizable_post_types', 'my_localizable_post_types', 10, 1 );
25
20
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
25
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?