
Nah bagaimana cara untuk menghilangkan caption tersebut pada halaman utama saja dan tetap memunculkannya pada halaman single page dalam website tersebut.
Kode awal functions.php
function limits($max_char, $more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
$content = strip_tags($content, '');
if (isset($_GET['p']) && strlen($_GET['p']) > 0) {
echo $content;
}
else if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) {
$content = substr($content, 0, $espacio);
$content = $content;
echo $content;
echo "...";
echo "<div class=";
echo "'rmore'>";
echo "<a href='";
the_permalink();
echo "'>".$more_link_text."</a></div>";
}
else {
echo $content;
}
}
Shortcode pada wordpress untuk caption biasanya di terapkan oleh filter :
$content = apply_filters('the_content', $content);
Sebagai contoh, Wordpress menciptakan kode berikut dalam konten Anda ketika Anda memasukkan keterangan gambar (Caption) :
[caption id="attachment_55" align="alignleft" width="127" caption="Here is my caption"][/caption]
Berikut Code khusus yang di gunakan dengan menambah string ganti untuk kode anda, dan ini hanya akan menghilangkan pada halaman depan.
$content = get_the_content($more_link_text, $stripteaser, $more_file);
// remove [caption] shortcode
$content = preg_replace("/\[caption.*\[\/caption\]/", '', $content);
// short codes are applied
$content = apply_filters('the_content', $content);
Saya hanya menambahkan kode
$content = preg_replace("/\[caption.*\[\/caption\]/", '', $content);