0

プラグインを作成しましたが、フロント エンドの任意のワードプレス ページからプラグイン ショートコードが埋め込まれたページに送信されるフォームを含むウィジェットを作成したいと考えています。

ウィジェットコード内で、ショートコードを含むページ/投稿またはパーマリンクを検出し、フォームの action="" にする必要があると思います。

誰もこれを行う方法を知っていますか?

見つかったショートコードに基づいて js/css を条件付きでロードするためのこのコードを見つけましたが、ウィジェットでの使用に適応する方法がわかりません。

add_filter('the_posts', 'conditionally_add_scripts_and_styles'); // the_posts gets triggered before wp_head
function conditionally_add_scripts_and_styles($posts){
if (empty($posts)) return $posts;

$shortcode_found = false; // use this flag to see if styles and scripts need to be enqueued
foreach ($posts as $post) {
    if (stripos($post->post_content, '[code]') !== false) {
        $shortcode_found = true; // bingo!
        break;
    }
}

if ($shortcode_found) {
    // enqueue here
    wp_enqueue_style('my-style', '/style.css');
    wp_enqueue_script('my-script', '/script.js');
}

return $posts;
}

ここにある元の投稿: http://beerpla.net/2010/01/13/wordpress-plugin-development-how-to-include-css-and-javascript-conditionally-and-only-when-needed-by-the -投稿/

どんな助けでも大歓迎です。ありがとう、ラス

4

0 に答える 0