質問編集履歴
1
誤字
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
|
-
|
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
|
-
|
21
|
+
$base_content = preg_replace('!<style.*?>.*?</style.*?>!is', '', $base_content);
|
12
|
-
|
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(' ', '', $trim_content);
|
26
|
+
|
27
|
+
};
|
28
|
+
|
29
|
+
echo $trim_content . '…';
|
30
|
+
|
31
|
+
};
|
32
|
+
|
13
|
-
|
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)で
|