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

質問編集履歴

1

誤字

2020/11/18 05:06

投稿

meli
meli

スコア312

title CHANGED
File without changes
body CHANGED
@@ -3,14 +3,35 @@
3
3
  サイトの記事抜粋部分にショートコードがそのまま表示されてしまい、非表示にしたいです。
4
4
  ショートコードを機能させるとキャプション画像が表示されてしまうので、ショートコード部分のみ非表示にするのが理想です。
5
5
 
6
- …\wp-content\themes\design\archive.php
7
- で記事抜粋の制御をしていると思うので、こちらに記述を加えたいです。
6
+ 以下で記事抜粋の制御をしていると思うので、こちらに記述を加えたいです。
8
7
 
9
8
  ```PHP
9
+ // オリジナルの抜粋記事 --------------------------------------------------------------------------------
10
+ function new_excerpt($a) {
11
+
10
- <?php }; ?>
12
+ if(has_excerpt()) {
13
+
14
+ $base_content = get_the_excerpt();
15
+ $base_content = str_replace(array("\r\n", "\r", "\n"), "", $base_content);
16
+ $trim_content = mb_substr($base_content, 0, $a ,"utf-8");
17
+
18
+ } else {
19
+
20
+ $base_content = get_the_content();
11
- <h4 class="title"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h4>
21
+ $base_content = preg_replace('!<style.*?>.*?</style.*?>!is', '', $base_content);
12
- <div class="excerpt"><?php if (has_excerpt()) { the_excerpt(); } else { new_excerpt(110);}; ?></div>
22
+ $base_content = preg_replace('!<script.*?>.*?</script.*?>!is', '', $base_content);
23
+ $base_content = strip_tags($base_content);
24
+ $trim_content = mb_substr($base_content, 0, $a ,"utf-8");
25
+ $trim_content = mb_ereg_replace('&nbsp;', '', $trim_content);
26
+
27
+ };
28
+
29
+ echo $trim_content . '…';
30
+
31
+ };
32
+
13
- </div>
33
+ //抜粋からPタグを取り除く
34
+ remove_filter( 'the_excerpt', 'wpautop' );
14
35
  ```
15
36
 
16
37
  こちらのサイト[https://elearn.jp/wpman/function/strip_shortcodes.html](https://elearn.jp/wpman/function/strip_shortcodes.html)で