add_action('enqueue_block_editor_assets', function () {
// まずCSSで「PDF設定」っぽい塊を隠す(保険)
wp_add_inline_style('wp-edit-blocks', '
/* ファイルブロックのサイドバー内「PDF設定」パネルを隠す(文言ベースはJSで) */
.block-editor-block-inspector .components-panel__body-title { }
');
// JSで「PDF設定」パネルを丸ごと削除(日本語/英語対応)
$js = <<<JS
(() => {
const TITLES = new Set(['PDF設定', 'PDF settings']);
const TOGGLE_LABELS = new Set(['インライン埋め込みを表示', 'Show inline embed']);
const removePdfPanel = (root) => {
if (!root) return;
// 1) パネル見出しが「PDF設定」のものを削除
root.querySelectorAll('.components-panel__body-title').forEach(titleEl => {
const t = (titleEl.textContent || '').trim();
if (TITLES.has(t)) {
const panel = titleEl.closest('.components-panel__body');
if (panel) panel.remove();
}
});
// 2) 見出しが変わっても、トグル文言が見つかったらそのパネルごと削除
root.querySelectorAll('.components-toggle-control__label').forEach(labelEl => {
const t = (labelEl.textContent || '').trim();
if (TOGGLE_LABELS.has(t)) {
const panel = labelEl.closest('.components-panel__body');
if (panel) panel.remove();
}
});
};
const boot = () => {
const inspector = document.querySelector('.block-editor-block-inspector');
if (!inspector) return;
removePdfPanel(inspector);
// Gutenbergは再描画が多いので監視して都度削除
const mo = new MutationObserver(() => removePdfPanel(inspector));
mo.observe(inspector, { childList: true, subtree: true });
};
if (window.wp?.domReady) {
wp.domReady(boot);
} else {
document.addEventListener('DOMContentLoaded', boot);
}
})();
JS;
// ハンドルは editor 系で確実に読み込まれるものに付ける
// wp-edit-blocks が無い環境もあるので wp-block-editor にも保険で付ける
wp_add_inline_script('wp-edit-blocks', $js, 'after');
wp_add_inline_script('wp-block-editor', $js, 'after');
});
ブロックエディタのPDF設定欄を消す
0
Last updated at Posted at 2026-03-02
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme