プラグインElementorのelementor/document/urls/editアクションの使用方法・解説

概要

elementor/document/urls/edit アクションは、ElementorでドキュメントのURLを編集する際に使用されるフックです。このアクションは、特にカスタムボタンやリンクの追加、コンテンツのカスタマイズなどの機能を実装する際に役立ちます。以下に、このアクションがよく使われるケースの一部を示します。

  1. カスタムテンプレート用のURL修正
  2. 外部リソースへのリンク追加
  3. 特定の条件に基づくURLの動的変更
  4. ユーザー入力に基づくリンク生成
  5. コンテンツの特定セクションへのジャンプリンク追加
  6. パラメータ付きURLの生成

構文

do_action('elementor/document/urls/edit', $document);

パラメータ

  • $document: 編集されるElementorドキュメントのオブジェクト。

戻り値

このアクション自体は戻り値を返しませんが、他のフックや関数に影響を与えることができます。

使用可能なバージョン

  • Elementor バージョン: 3.0以降
  • WordPress バージョン: 5.0以降

この関数のアクションでの使用可能性

アクション 使用例
mu_plugin_loaded
registered_post_type
plugins_loaded
wp_roles_init
setup_theme
after_setup_theme
set_current_user
init
register_sidebar
wp_loaded
send_headers
parse_query
pre_get_posts
wp
template_redirect
get_header
wp_head

サンプルコード

サンプル1: カスタムURLの追加

このサンプルコードは、特定の条件に基づいてカスタムURLをダッシュボードに追加します。

add_action('elementor/document/urls/edit', function($document) {
    if ($document->get_title() === '特定のページタイトル') {
        $document->add_url('custom_url', 'https://example.com/custom');
    }
});

サンプル2: 外部リソースのリンク設定

このコードは、特定の要素に外部リソースへのリンクを追加します。

add_action('elementor/document/urls/edit', function($document) {
    $document->add_url('external_link', 'https://external-resource.com');
});

サンプル3: 動的なURL編集

ユーザーの入力に基づいて、URLを動的に変更するサンプルです。

add_action('elementor/document/urls/edit', function($document) {
    $dynamic_url = get_user_meta(get_current_user_id(), 'custom_url', true);
    if ($dynamic_url) {
        $document->add_url('dynamic_url', esc_url($dynamic_url));
    }
});

サンプル4: セクションジャンプリンクの追加

このコードでは、特定のセクションへのリンクを作成します。

add_action('elementor/document/urls/edit', function($document) {
    $document->add_url('section_jump', '#sectionId');
});

サンプル5: パラメータ付きURL

このサンプルでは、特定のクエリパラメータを持つURLを生成します。

add_action('elementor/document/urls/edit', function($document) {
    $param_url = 'https://example.com/?ref=custom_param';
    $document->add_url('param_url', esc_url($param_url));
});

これらのサンプルは、ElementorでのURL編集におけるelementor/document/urls/edit フックの活用方法を示しています。各コードスニペットは、特定の機能や条件に応じたカスタムURLを追加する方法を示しており、それぞれが独自の目的に基づいています。

引用元のページは、Elementorの公式文書やGitHubリポジトリを参照してみてください。

この関数について質問する


上の計算式の答えを入力してください