PHP
[WordPress] 記事中に特定のショートコードが含まれているかをチェックする方法
2017年10月13日<?phpglobal $post;// [news_topics] というショートコードが含まれているかif( has_shortcode( $post->post_content, 'news_topics' ) ) { // 何らかの処理}
<?phpglobal $post;// [news_topics] というショートコードが含まれているかif( has_shortcode( $post->post_content, 'news_topics' ) ) { // 何らかの処理}
<?php/** * 外部リンクページのリダイレクト処理 */function oc_template_redirect() { if ( is_page() ) { $status = 302; $location = ""; $post_id = get_queried_object_id(); // 外部サイトへリダイレクトするためのカスタムフィールドを取得 $location = get_post_meta($post_id, "oc_external_link_url", true); // 空でなければリダイレクト(状況によってはURLの文字列チェック等がいるかも) if(!empty($location) ) { wp_redirect( $location, $status ); exit; } }}add_action( 'template_redirect', 'oc_template_redirect' );