2
1

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.

Breadcrumb NavXTでリストの途中に項目を追加する

Posted at

内容

Breadcrumb NavXTのbcn_after_fillアクションでリストの途中に項目を追加する方法です。
array_splice関数を使用しますが、この関数のreplacementパラメータは、実行時に配列への強制的な変換を行います。このため、new bcn_breadcrumb()で生成したインスタンスをそのまま引数にすると分解されてしまうので要注意です。単数のインスタンスでも、意図しない変換が行われないように配列へ代入しておきます。

コード

functions.php
function bcn_insert_test($breadcrumb_trail) {
  $breadcrumb = new bcn_breadcrumb();
  $breadcrumb->set_title('test');
  $breadcrumb->set_url(home_url('test/'));
  array_splice($breadcrumb_trail->breadcrumbs, 1, 0, [$breadcrumb]);
  return $breadcrumb_trail;
}
add_action('bcn_after_fill', 'bcn_insert_test');
2
1
0

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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?