Skip to content

Instantly share code, notes, and snippets.

@JuReyms
Last active March 30, 2022 20:42
Show Gist options
  • Save JuReyms/dc06149ff91bb81b1285292d20323986 to your computer and use it in GitHub Desktop.
Save JuReyms/dc06149ff91bb81b1285292d20323986 to your computer and use it in GitHub Desktop.
WordPress - Text without img & Img without text
<?php
function text_post(){
// Post text without img
$content = nl2br(get_the_content());
$postOutput = preg_replace('/<img[^>]+./', '', $content);
echo $postOutput;
}
function img_post() {
// img without post
$attachments = get_children(array(
'include' => $ids,
'post_type' => 'attachment',
'post_mime_type' => 'image',
'posts_per_page' => -1,
'order' => 'asc',
'orderby' => 'menu_order ID',
'post_parent' => get_the_ID(),
'exclude' => get_post_thumbnail_id()
));
if ($attachments) {
foreach ($attachments as $attachment) {
$attachment_title = $attachment->post_title;
echo wp_get_attachment_image($attachment->ID, 'large', '', array("alt" => $attachment_title, "title" => $attachment_title), true);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment