Try this code in your theme’s functions.php
file-
function filtered_content($content){
$content = preg_replace("/<img[^>]+\>/i", "", $content); // removes images
$content = preg_replace('/<iframe.*?>/', "", $content); // removes iframes
return $content;
}
add_filter('the_content', 'filtered_content');
This will remove img and iframe tag from your content. Then use the_content()
in your template.
Related Posts:
- WordPress Ajax filter: Create two loops for different output styles?
- For each loop will not append to the_content hook
- adding a filter to a shortcode?
- Permanently remove first image from posts
- Change the footer text on the login page
- Displaying post per day
- How to overwrite youtube embed?
- Rewriting search and pagination base
- Filter the blog title displayed in the header
- Post from one loop in different containers?
- append PHP function to the_content
- Custom Loop Pagination on WordPress
- delete an array element when its date expires
- User Defined order on get_categories?
- get understrap pagination to work with custom query
- How to add Shortcode (font awesome) in widget title?
- When would you use $_post instead of $post?
- Wrap First Character after in a tag
- Way to display “Yesterday”, “Today”
- WooCommerce: Add Payment Gateway Field to Webhooks [closed]
- Must Use Plugin Causing Query Error
- Advanced Custom Fields: Post Object – Not returning data [closed]
- How to call function at the bottom of post using plugin?
- multiple if statements [closed]
- How does the ternary operator work in the wordpress loop post?
- Get_avatar filter?
- How can I add multiple ‘tax_query’ arrays via a loop?
- Is it acceptable to treat a filter like an action?
- Edit incorrect password message WordPress
- Why does my callback function not work with this custom filter hook?
- Contact Fom 7 – how to add custom HTML inside span.wpcf7-form-control-wrap AND IMMEDIATELY AFTER input.wpcf7-form-control?
- Generating an nonce for Content Security Policy and all scripts – How to make it match/persist for each page load?
- Blog posts repeat
- Unique icons next to each WordPress menu item
- How to set variable, pass it to a partial file and remove it after?
- Can’t find infinite loop cause
- Checkbox doesn’t stay checked, conten
- List posts that don’t have a specific tag?
- Add content after the first post in WP Loop
- Display an image if odd number of posts in grid
- How to loop through all the attached images in a post, and get their url one by one
- 2nd page displaying the exact same posts as my first page (minus the very first post)
- Content filter won’t work
- Is the 404 page automatically displayed if a loop returns nothing?
- Show recent posts starting at a specific number archive
- Warning: in_array() null given in PHP function
- How to pass a variable to get_template_part that’s updated every time the template part is called?
- Issue with custom loop in Archive page
- use loop to return blog details
- How do I create a secondary version of the_content
- WP Query Leads to 502 Bad Gateway (Timeout Because Query Takes Too Long)
- Get the_content surrounded by instead of
- home.php show blog posts as grid view
- How to add post meta in while loop?
- Displaying content on posts page based on category
- Calling function in loop causes repeat data
- WordPress call post-ID in jquery
- How to Generate a list of Most Commented post?
- How to pick “full/thumbnail” images in the loop?
- How to Fix an Archive.php That Displays All Posts?
- List all anchor links on a page
- How to add ASCII symbol after each recent post [closed]
- Search.php gets metadata from first post
- WordPress doesn’t load HTML
- the_post(); prints out style text into my HTML?
- How can I modify this code to make the search box include tags and meta
- How do I make these combination select filters work when only one dropdown is set? They work in WordPress 5.8.2 but don’t in 5.8.3
- Show related products by attribute based and certain conditions
- Copying and pasting to WordPress “code editor” code via the front end and clipboard
- How to run php code only for a specific widget on a page and not all widgets on that page?
- Change the “Show All” button in a WordPress Portfolio Filter
- Trim Titles Only On Some Pages
- update_user_meta as multiple value but with same meta key
- How to bind each “the_content” elements to a custom variables
- add_filter() inside another add_filter()
- Accordion headings cuts off to second line on collapsing a accordion heading (used acf repeater)
- WordPress Recent Posts – Loop
- ACF background-color per post in a WordPress loop
- Custom Bulk Actions handler not firing
- Advertisement in Loop Posts wordpress
- dynamically change content of div with php
- PHP for loop not working as intended
- Adding custom PHP to existing loop in Genesis
- How to Pass Current Taxonomy Terms into new WP_Query?
- For each 3 posts, show a different post type
- Loop returns more items than exist?
- Modify category archive page loop on functions.php
- WP_Post is not from correct array
- Post formating on Home page
- divide custom field values in div every two values
- Limit ads appearing more than three times
- Pagination on Custom Loop
- What is the best way to get the first few post from WordPress in different divs using a loop?
- Search box background on a different page template
- Custom single.php files for different post formats
- Troubleshooting “loopback requests that take too long”
- Loop on a wordpress Page instead of content coming from the WP text editor
- How to create a loop where loop changes every post?
- Help with if/else loop [closed]
- How to change wp-admin and wp-login urls