• ベストアンサー
※ ChatGPTを利用し、要約された質問です(原文:wordpressのadd_action関係)

WordPressのadd_action関係について

このQ&Aのポイント
  • WordPressのadd_action関数についての質問です。特に、第1引数の役割やif文との違いが知りたいです。
  • WordPressのadd_action関数に関連する質問です。第1引数やif文の役割について教えてください。
  • WordPressのadd_action関数に関する疑問です。第1引数やif文の違いが分かりません。解説していただけますか?

質問者が選んだベストアンサー

  • ベストアンサー
回答No.1

wp_enqueue_scriptsというhookは wp_enqueue_script()を適切なタイミングで行う為のhookです つまるところwp_enqueue_scriptで使う為の wp_register_scriptでの登録とかがちゃんと 終わったタイミングってとこでしょうか 公式によるとwp_enqueue_scriptsというhookは wp_enqueue_scriptsという名前だけど wp_enqueue_script()とwp_enqueue_style() 両方の適切なタイミングで行う為のhookだそうです add_action( 'wp_enqueue_scripts2', 'my_scripts' );が ちゃんと動いてしまうのは、無効な名前のhookも どこかのタイミングで実行されているからってことなのかもしれませんが そこはちょっと確認できてません

全文を見る
すると、全ての回答が全文表示されます。

関連するQ&A

  • HTMLをWordPress化 CSSをどこに?

    HTMLをWordPress化にするための勉強をしています。 HTML側 CSS ヘッダー内 <link rel="stylesheet" href="css/test.css"> <link rel="stylesheet" href="css/test2.css"> JS ヘッダー内ではなく一番下</body>の前に配置 <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script> <script src="js/test1.js"></script> <script src="js/test2.js"></script> ★これをfunctions.php に記述するにはどうすれば良いのでしょうか? function sample_scripts() {   // CSSの読み込み   wp_enqueue_style( 'jdsa-style', get_template_directory_uri().'/css/test.css', array(), '1' );   wp_enqueue_style( 'jdsa-style', get_template_directory_uri().'/css/test2.css', array(), '1' );   // jqueryの読み込み wp_deregister_script( 'jquery' ); wp_enqueue_script( 'jquery', get_template_directory_uri().'https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js', array(), '1.10.3', true );   // サイト内のjsの読み込み   wp_enqueue_script( 'jdsa-script', get_template_directory_uri().'/js/test1.js', array(), '1', true );   wp_enqueue_script( 'jdsa-script', get_template_directory_uri().'/js/test2.js', array(), '1', true ); }//ここまで 結果 ヘッダー内にtest.cssのみ記載、test2.cssは記載していない。 jsはどこにも記載していませんでした。 どこが間違っておりますか? 宜しくお願いします。

    • ベストアンサー
    • PHP
  • CSSが反映されない

    以前にも質問させていただいたのですが、解決しなかったので、再度質問させていただきます。 ワードプレスのCSSが反映されません。 編集場所は子テーマのCSSです。 最初に .headline2{ background-color:#ffd700; } でダメで、こちらで質問させていただいたところ ・・・・・・・・・・・・・・・・・・・・・・・・・・・・ 子テーマの functions.php にて親テーマのスタイルを生かしつつ子テーマに追加のスタイルを記述するアクションを追加します。 add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' ); function theme_enqueue_styles() { wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' ); wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array('parent-style') ); } ・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・ という回答をいただいたので、functions.php にコピペしましたが、ダメでした。 それからネットでいろいろと調べていて、優先度というものを知りまして 前 .headline2{ background-color:#ffd700; } 後 #content h2{background-color:#ffd700;} の指定をしてみたのですが、そもそも更新をはねのけられました。 次に どうしてもうまくいかないなら スタイルの最後に「!important」を付ける方法もありますとあったので #content h2{background-color:#ffd700; !important} としてみました が、これも更新ができませんでした。 解決方法わかりますか?

    • 締切済み
    • CSS
  • 関数「create_function」について

    WordPressのテーマで、下記について質問です。 if($this->options['general']['clean_exerpts']) { add_filter('excerpt_more', create_function('', 'return "";') ); } if($this->options['general']['hide_wp_version']) { add_filter('the_generator', create_function('', 'return "";') ); } create_functionを使わないで別の関数を使いなさいと エラーが表示されるのですが、公式によると function() { // do something }); を使いなさいとあります。 上記PHPコードの場合、 add_filter('the_generator', function() {'', 'return "";'}); ); で合ってますか?教えてください

    • ベストアンサー
    • PHP
  • WordPressのテーマのphpのエラーについて

    WordPressのテーマを編集中に構文エラーが起きました。 phpについてはあまり詳しくないので是非わかる方がいればお力を貸していただきたいです。 『syntax error, unexpected T_ENDIF in ~/functions.php on line 100』とでて問題のコードは 下記の辺りではないかと思っています。 if ( function_exists( 'wp_get_theme' ) ) { add_theme_support( 'custom-background', $args ); } else { define( 'BACKGROUND_COLOR', $args['default-color'] ); define( 'BACKGROUND_IMAGE', $args['default-image'] ); add_theme_support( 'custom-background', $args ); } endif; // mon_cahier_setup add_action( 'after_setup_theme', 'mon_cahier_setup' ); コードの全文は下記のリンク先にあります。 http://codepad.org/caNvP1Hi いろいろ調べてみたつもりですが、具体的な解決策はわからないままです。 どうぞよろしくお願いします。

    • ベストアンサー
    • PHP
  • あるカテゴリーの固定ページ一覧/WordPress

    <?php wp_list_pages('title_li='); ?>で固定ページ一覧が表示されますが あるカテゴリーの固定ページに限定して一覧表示できないでしょうか。 固定ページにカテゴリーを設定は、functions.phpに add_action('init','add_categories_for_pages'); function add_categories_for_pages(){ register_taxonomy_for_object_type('category', 'page'); } add_action( 'pre_get_posts', 'nobita_merge_page_categories_at_category_archive' ); function nobita_merge_page_categories_at_category_archive( $query ) { if ( $query->is_category== true && $query->is_main_query() ) { $query->set('post_type', array( 'post', 'page', 'nav_menu_item')); } } と記述して、解決しています。

    • ベストアンサー
    • PHP
  • WP2.7.1でコメントの日付の表記を変更

    ワードプレス2.7.1を使っています。 コメント表示の日付の表記が 2009 年 5 月 18 日 となっているので、 2009/5/18 と直したいのですが、どこをどうしたらいいのか… wp/wp-includes/comment-template.php の350行目あたりにそれっぽいのがあるのですが function get_comment_date( $d = '' ) { global $comment; if ( '' == $d ) $date = mysql2date( get_option('date_format'), $comment->comment_date); else $date = mysql2date($d, $comment->comment_date); return apply_filters('get_comment_date', $date); } これでしょうかね?色々やってみましたらエラーになります…

  • Wordpressのコメント欄受付・表示について。

    WordPress 2.8.6で構築 現在全てのブログでコメント受付が非表示になっていますが、その中の1つのカテゴリのブログだけでコメント欄を表示させるのが目的です。 phpの知識が追い付かずネットでも解決方法が見つけられず、以下のcomments.phpを修正してカテゴリの設定を変更するイメージでしたが理解が追い付きません。 どなたかお詳しい方いらっしゃいますでしょうか? <?php // Do not delete these lines if (isset($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME'])) die ('Please do not load this page directly. Thanks!'); if ( post_password_required() ) { ?> <p class="nocomments"><?php _e('This post is password protected. Enter the password to view comments.', 'kubrick'); ?></p> <?php return; } ?> <!-- You can start editing here. --> <?php if ( have_comments() ) : ?> <h3 id="comments"><?php comments_number(__('No Responses', 'kubrick'), __('One Response', 'kubrick'), __('% Responses', 'kubrick'));?> <?php printf(__('to “%s”', 'kubrick'), the_title('', '', false)); ?></h3> <div class="navigation"> <div class="alignleft"><?php previous_comments_link() ?></div> <div class="alignright"><?php next_comments_link() ?></div> </div> <ol class="commentlist"> <?php wp_list_comments();?> </ol> <div class="navigation"> <div class="alignleft"><?php previous_comments_link() ?></div> <div class="alignright"><?php next_comments_link() ?></div> </div> <?php else : // this is displayed if there are no comments so far ?> <?php if ( comments_open() ) : ?> <!-- If comments are open, but there are no comments. --> <?php else : // comments are closed ?> <!-- If comments are closed. --> <p class="nocomments"><?php _e('Comments are closed.', 'kubrick'); ?></p> <?php endif; ?> <?php endif; ?> <?php if ( comments_open() ) : ?> <div id="respond"> <h3><?php comment_form_title( __('Leave a Reply', 'kubrick'), __('Leave a Reply for %s' , 'kubrick') ); ?></h3> <div id="cancel-comment-reply"> <small><?php cancel_comment_reply_link() ?></small> </div> <?php if ( get_option('comment_registration') && !is_user_logged_in() ) : ?> <p><?php printf(__('You must be <a href="%s">logged in</a> to post a comment.', 'kubrick'), wp_login_url( get_permalink() )); ?></p> <?php else : ?> <form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform"> <?php if ( is_user_logged_in() ) : ?> <p><?php printf(__('Logged in as <a href="%1$s">%2$s</a>.', 'kubrick'), get_option('siteurl') . '/wp-admin/profile.php', $user_identity); ?> <a href="<?php echo wp_logout_url(get_permalink()); ?>" title="<?php _e('Log out of this account', 'kubrick'); ?>"><?php _e('Log out &raquo;', 'kubrick'); ?></a></p> <?php else : ?> <p><input type="text" name="author" id="author" value="<?php echo esc_attr($comment_author); ?>" size="22" tabindex="1" <?php if ($req) echo "aria-required='true'"; ?> /> <label for="author"><small><?php _e('Name', 'kubrick'); ?> <?php if ($req) _e("(required)", "kubrick"); ?></small></label></p> <p><input type="text" name="email" id="email" value="<?php echo esc_attr($comment_author_email); ?>" size="22" tabindex="2" <?php if ($req) echo "aria-required='true'"; ?> /> <label for="email"><small><?php _e('Mail (will not be published)', 'kubrick'); ?> <?php if ($req) _e("(required)", "kubrick"); ?></small></label></p> <p><input type="text" name="url" id="url" value="<?php echo esc_attr($comment_author_url); ?>" size="22" tabindex="3" /> <label for="url"><small><?php _e('Website', 'kubrick'); ?></small></label></p> <?php endif; ?> <!--<p><small><?php printf(__('<strong>XHTML:</strong> You can use these tags: <code>%s</code>', 'kubrick'), allowed_tags()); ?></small></p>--> <p><textarea name="comment" id="comment" cols="100%" rows="10" tabindex="4"></textarea></p> <p><input name="submit" type="submit" id="submit" tabindex="5" value="<?php _e('Submit Comment', 'kubrick'); ?>" /> <?php comment_id_fields(); ?> </p> <?php do_action('comment_form', $post->ID); ?> </form> <?php endif; // If registration required and not logged in ?> </div> <?php endif; // if you delete this the sky will fall on your head ?>

    • ベストアンサー
    • PHP
  • [jQuery] クリックで連番関数を順番に実行

    ボタンをクリックする度に連番で作成した関数を順番に実行したいのですが、スマートな書き方がわかりません。 下記のコードで一応動くのですが、関数が100個とかに増えた場合すごくコードが長くなってしまいます。 もっとスマートに書く方法はないものでしょうか? ▼サンプルコード <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script> $(function(){ function s1(){alert('s1');}; function s2(){alert('s2');}; function s3(){alert('s3');}; var num = 1; $('p').click(function() { if(num == 1){s1();} else if(num == 2){s2();} else if(num == 3){s3();} num++; return false; }); }); </script> </head> <body> <p>click</p> </body> </html>

  • フォームについて

    <head> <title></title> <script type="text/javescript"> function reply() { alert("aa"); } </script> </head> <body> <form name="f1" action="#"> cc <input type="button" name="dd" value="確認" onclick="confirm('OK?');"> こんな感じで使ったのですが、 function reply() { alert("aa"); } ここの意味がわかりません。 あと、これでやると「OK」と「キャンセル」が出るのですが、 [ok]を押すとブラウザ上に何か出て、「キャンセル」を押すと、また違う文が出るという風にしたいのですが、 それをif else文でやりたいのですが、 どこに入れればいいのかわかりません。 どなたか教えてください。

  • Wordpressでのプログラムの競合重複について

    現在Wordpressのサイト制作で、jqueryプラグインを複数導入しようとしているのですが、 それぞれのプログラムが競合してしまい上手く動作してくれません。 記述する順番を変更したりwp_enqueue_scriptやnoConflictを試したのですが、 私の知識不足で競合の解消には至っておりません。 どこかのサイトでjqueryを読み込む際は一つでいいと確認したので、 最上部に記述しているのですがスライドショーとニュースティッカーの部分が動かない状態です。 個人的に考えられる原因としては ・それぞれのプログラムのjqueryのバージョンが違うこと ・header内のjavascriptの$が複数使われていることによる競合 だと思うのですが、 どなたか詳しい方がおられたら教えて頂けませんでしょうか? 以下、head内の問題のソースです。 何卒よろしくお願いいたします。 <head profile="http://gmpg.org/xfn/11"> ~ <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script> <script type="text/javascript" src="http://~/wp-content/themes/~/javascript/jquery.easing.js"></script> <script type="text/javascript" src="http://~/wp-content/themes/~/javascript/jquery.kwicks.js"></script> <script type="text/javascript"> $().ready(function() { $('.kwicks').kwicks({ max : 200, duration: 1000, easing: 'easeOutQuint' }); }); </script> <script type="text/javascript" src="http://~/wp-content/themes/~/javascript/simplegallery.js"></script> <script type="text/javascript"> $(function() { var mygallery=new simpleGallery({ wrapperid: "simplegallery1", /* ギャラリーを表示する要素のID名 */ dimensions: [640, 300], /* 画像の幅、高さ(単位:ピクセル) */ imagearray: [ /* [画像URL、リンク先URL、_new] */ ["<?php bloginfo('template_directory'); ?>/images/bnr/bnr-preopen.png", ""], ["<?php bloginfo('template_directory'); ?>/images/bnr/bnr_aisatu.png","http://~.com/?page_id=74"], ], autoplay: true, /* 自動再生の有無 */ persist: true, pause: 3500, /* スライドする間隔(ミリ秒) */ fadeduration: 2000, /* フェードする移行時間(ミリ秒) */ oninit:function(){ //event that fires when gallery has initialized/ ready to run }, onslide:function(curslide, i){ //event that fires after each slide is shown //curslide: returns DOM reference to current slide's DIV (ie: try alert(curslide.innerHTML) //i: integer reflecting current image within collection being shown (0=1st image, 1=2nd etc) } }) }); </script> <script src="http://~/wp-content/themes/~/javascript/jquery.ticker.js" type="text/javascript"></script> <script src="http://~/wp-content/themes/~/javascript/site.js" type="text/javascript"></script> </head> <?php wp_head(); ?>

FAXが受信できなくなった
このQ&Aのポイント
  • MFC-J6999CDWのFAX受信ができない状況に至りました。
  • 送信はできるが受信ができないトラブルが発生し、着信中の表示が多発しています。
  • おそらくアナログ回線を使用しているため、受信できない原因がある可能性があります。
回答を見る

専門家に質問してみよう