teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

プラグインやfunctions.php・固定ページの内容を追記

2020/03/05 10:22

投稿

murama2
murama2

スコア113

title CHANGED
File without changes
body CHANGED
@@ -3,9 +3,14 @@
3
3
  どう設定すれば、表示されるようになりますでしょうか。
4
4
 
5
5
  WordPressバージョン:5.2.3
6
+ プラグイン:Multi Device Switcher
6
7
  ※マルチデバイススイッチャーでスマホにも対応
7
8
 
9
+
10
+ ■functions.phpの内容
8
11
  ```ここに言語を入力
12
+ <?php
13
+
9
14
  /*
10
15
  最新情報ショートコード
11
16
  [newspost cat="x" show="3"]
@@ -49,6 +54,138 @@
49
54
  }
50
55
  // クエリのリセット
51
56
  wp_reset_postdata();
52
- return $output;
57
+ return do_shortcode($output);
53
58
  }
59
+
60
+
61
+ //アイキャッチ画像
62
+ add_theme_support( 'post-thumbnails' );
63
+
64
+ //抜粋文字数変更
65
+ function new_excerpt_mblength($length) {
66
+ return 100;
67
+ }
68
+ add_filter('excerpt_mblength', 'new_excerpt_mblength');
69
+
70
+ //抜粋文末文字変更
71
+ function new_excerpt_more($more) {
72
+ return '...';
73
+ }
74
+ add_filter('excerpt_more', 'new_excerpt_more');
75
+
76
+
77
+ //ウィジェット追加
78
+ if (function_exists('register_sidebar')) {
79
+
80
+ register_sidebar(array(
81
+ 'name' => 'サイドバー1',
82
+ 'id' => 'sidebar1',
83
+ 'description' => 'ブログ用',
84
+ 'before_widget' => '<div class="cont-box">',
85
+ 'after_widget' => '</div>',
86
+ 'before_title' => '<h2>',
87
+ 'after_title' => '</h2>'
88
+ ));
89
+ }
90
+
91
+ //スラッグ取得
92
+ function get_page_child_uri($page_id) {
93
+ $page = get_post($page_id);
94
+ return $page->post_name;
95
+ }
96
+
97
+ // 「投稿」名称変更
98
+ function change_post_menu_label() {
99
+ global $menu;
100
+ global $submenu;
101
+ $menu[5][0] = 'BLOG投稿';
102
+ $submenu['edit.php'][5][0] = '投稿一覧';
103
+ $submenu['edit.php'][10][0] = '新しい投稿';
104
+ $submenu['edit.php'][16][0] = 'タグ';
105
+ //echo ”;
106
+ }
107
+ add_action( 'admin_menu', 'change_post_menu_label' );
108
+
109
+
110
+ //headの不要なものとをトル
111
+ remove_action('wp_head','wp_generator');
112
+ remove_action('wp_head', 'print_emoji_detection_script', 7 );
113
+ remove_action('wp_print_styles', 'print_emoji_styles' );
114
+ remove_action('wp_head','rest_output_link_wp_head');
115
+ remove_action('wp_head','wp_oembed_add_discovery_links');
116
+ remove_action('wp_head','wp_oembed_add_host_js');
117
+
118
+ //固定ページの自動整形無効
119
+ function disable_page_wpautop() {
120
+ if ( is_page() ) remove_filter( 'the_content', 'wpautop' );
121
+ }
122
+ add_action( 'wp', 'disable_page_wpautop' );
123
+
124
+
125
+ //サイトURLを取得
126
+ add_shortcode('url', 'shortcode_url');
127
+ function shortcode_url() {
128
+ return get_bloginfo('url');
129
+ }
130
+
131
+ //アップロード・ディレクトリのパスを取得
132
+ add_shortcode('upload', 'shortcode_up');
133
+ function shortcode_up() {
134
+ $upload_dir = wp_upload_dir();
135
+ return $upload_dir['baseurl'];
136
+ }
137
+
138
+ function shortcode_templateurl() {
139
+ return get_bloginfo('template_url');
140
+ }
141
+ add_shortcode('temp_url', 'shortcode_templateurl');
142
+
143
+
144
+
145
+
146
+ //投稿メディア設定
147
+ add_filter( 'image_send_to_editor', 'remove_image_attribute', 10 );
148
+ add_filter( 'post_thumbnail_html', 'remove_image_attribute', 10 );
149
+
150
+ function remove_image_attribute( $html ){
151
+ $html = preg_replace( '/(width|height)="\d*"\s/', '', $html );
152
+ $html = preg_replace( '/class=[\'"]([^\'"]+)[\'"]/i', '', $html );
153
+ $html = preg_replace( '/title=[\'"]([^\'"]+)[\'"]/i', '', $html );
154
+ $html = preg_replace( '/<a href=".+">/', '', $html );
155
+ $html = preg_replace( '/</a>/', '', $html );
156
+ return $html;
157
+ }
158
+ add_action( 'admin_print_styles', 'admin_css_custom' );
159
+ function admin_css_custom() {
160
+ echo '<style>.attachment-details label[data-setting="caption"], .attachment-details label[data-setting="description"], div.attachment-display-settings { display: none; }</style>';
161
+ }
162
+
163
+ //店舗紹介ニュース一覧
164
+ function Include_my_php($params = array()) {
165
+ extract(shortcode_atts(array(
166
+ 'file' => 'default'
167
+ ), $params));
168
+ ob_start();
169
+ include(get_theme_root() . '/' . get_template() . "/$file.php");
170
+ return ob_get_clean();
171
+ }
172
+
173
+ add_shortcode('myphp', 'Include_my_php');
174
+
175
+ ?>
176
+
177
+ ```
178
+
179
+ ■固定ページ
180
+ [multi][/multi]の間に新着情報出力用のショートコードを入れると表示されないみたいです。
181
+ [multi][/multi]がない固定ページでは正常に表示されるのを確認いたしました。
182
+ ※ショートコード以外の内容は割愛させていただきます。
183
+ ```ここに言語を入力
184
+ [multi device="smart"]
185
+ スマホ用のコード
186
+ [/multi]
187
+ [multi]
188
+ PC用のコード
189
+ [newspost cat="12" show="3"]
190
+ [/multi]
54
191
  ```