Omit image captions from get_the_content()

I use a theme that calls get_the_content() to display short excerpts of the latest blog posts on the home page. Now I noticed that the excerpt sometimes starts with an image caption, if the blog post contains a picture at the very beginning. I usually do that and make the text float around it. I always set the first three caption fields on an image (Alt Text, Title, Caption). Is there any way to strip these image captions from the …
Category: Web

Include custom fields into the content of a regular page

Here's my setup: Parent "Gallery" page: _regular page, not custom type or anything _ Several "Project" child pages (could be as few as 1, unlimited number): also normal pages Child pages will either have meta boxes or custom fields for entering stuff into my pre-formatted areas. I don't care if it's meta boxes or custom fields, whatever is figure-outable! I'm using standard WP-provided code to show Child page titles and the_content on the Parent page. <?php $mypages = get_pages( array( …
Category: Web

Add Image Before Posts Entry Title

This code adds the image before all titles on the page. How do i add one single image before the posts entry title? function adt_abovetitle($title){ //Return new title if called inside loop if ( in_the_loop() ) { $x = do_shortcode('[shortcode id="'. $id . '"]'); return $x . $title; } else { //Else return regular return $title; } } add_filter( 'the_title', 'adt_abovetitle');
Category: Web

Post and page content not displaying in search results

I am using a content-search.php template part to output my search results. The post/page titles and links to those posts/pages are working correctly, but for some reason the the_content() function is not rendering any HTML. I have tested for errors with debugging on, but nothing is displayed. Here is my content-search.php template code: <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <header class="entry-header"> <?php the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); ?> </header><!-- .entry-header --> <div …
Category: Web

how to print the content of pages inside the front end area

i'm new to wordpress and i'm trying to create a website. i need display the content of the pages when corresponding menu items are clicked. my page.php contain <?php while ( have_posts() ) : the_post(); $page_data= $post->ID; if($page_data=='116') { ?> <center><b><h2>WELCOME TO THE CLINIC!!</h2></b></center> <?php } else{ ?> <h1 class="entry-title"><?php the_title(); ?></h1> <?php the_content(); } endwhile; ?> but my content is not displaying. title is showing properly. what is the mistake in the code? please help me.
Category: Web

How do I add the featured image to the_content after the first paragraph?

My problem: I'm trying to create a filter that will add the featured image of a post to the_content, so that I can have the first paragraph of the_content displayed before this image. What I basicly want to achieve: <p>First Paragraph of the_content</p> <img>The Post's Featured Image</img> <p>The rest of the_content</p> I someone is able to help me. Thanks in advance!
Category: Web

Remove External Links from WordPress posts Using add_filter() in Theme functions.php

We have been searching high an low for a plugin, code sample or example of how to remove all external links at the theme filter level but can't seem to find anything online. We want to keep the external links in the actual post database entry but simply remove them using add_filter() inside the theme's functions.php file so we can add them again when we need to. We would also need to filter out links for the domain the site …
Category: Web

Get featured image from post on RSS feed

I want to add the featured image to my RSS feed. function rss_post_thumbnail($content) { global $post; if(has_post_thumbnail($post->ID)) { $content = '<p>' . get_the_post_thumbnail($post->ID) . '</p>' . get_the_content(); } return $content; } add_filter('the_excerpt_rss', 'rss_post_thumbnail', 20, 1); add_filter('the_content_feed', 'rss_post_thumbnail', 20, 1); With this snippet the thumbnail is shown, but the content is not generated correct. It is shown with shortcodes and its not formatted... When i use the snippet below, where i remove the ordering of filters, the content is shown, but …
Category: Web

Filter post style attribute

Looking for a hook which enables filtering of a class within the post or content so i can add inline CSS using custom fields for posts on the home page. Something like this - add_filter( 'attr_entry', 'filter_post_html_tag' ); function filter_post_html_tag( $attributes ) { $color = get_post_meta( get_the_ID(), 'background_color', true ); $colors = $color ? $color : 'grey'; $attributes['style'] = 'color:' . $colors . ''; return $attributes; }
Category: Web

Replace the_content with ACF Flexible Content via function

function replace_the_content($content) { global $post; // ACF post summary if (get_field('post_summary')) : $post_summary = '<h4> ' . get_field('post_summary') . '</h4>'; endif; // ACF "More information" if( have_rows('more_information') ): while( have_rows('more_information') ): the_row(); $more_info = ' <div> <div>'.get_sub_field('column_1') .'</div> <div>'.get_sub_field('column_2') .'</div> </div> '; endwhile; endif; // To replace the_content $the_post = ' <div> '.$post_summary.' </div> <div> '.$more_info.' </div> '; return $the_post; } return $content; } add_filter('the_content', 'replace_the_content'); This works, but now I want to get an ACF Flexible Content field in …
Category: Web

How to stop DOMDocument destroying embeds?

I am making use of PHP's DOMDocument to carry out two DOM operations on the post content, by filtering the_content: Wrap a certain element pattern in a div. Add a class to a particular element. The trouble is, it seems like DOMDocument is destroying embedded WordPress content like tweets. As seen in this example, the embedded tweet is not rendered as an <iframe> as it should be, it is just rendered using <p>. Is there a way to stop DOMDocument …
Category: Web

Filter content for get_the_content()

I Need to filter content for posts. If the user is not logged in, then the post content should display "please log in....". If he is logged in, then he can see the post content. I wrote the filter: add_filter('the_content', 'check_user_logedin',10); function check_user_logedin($content){ global $post; if ( $post->post_type == 'do_pobrania' && has_term( 'zabezpieczony','rodzaj_plikow' ) && !is_user_logged_in() ) { return $content ='My text'; }else{ return $content; } } And here comes my problem, because the plugin I use uses get_the_content() and …
Category: Web

add css to only body text

In my single wordpress posts I want to apply a padding of 100px to the left and right. The problem is that when I apply it to .single .post-content the images also get a padding. However, I want all of the images on the posts pages to be set to 100%. Is there a way to separate the actual body text and the images? This seems like a fairly simple question. But I can't figure it out. Any help is …
Category: Web

how to use custom loop in the_content filter

Trying to use the the below code for my CPT 'state' like add_filter('the_content', 'my_custom_loop'); but the trial and error is not getting me anywhere. I can't use a single-{post_type}.php since i am using a drag and drop theme headway. Update: exact code I am trying to use in a functionality plugin and it gives me a warning include-once with debug on or a blank white screen function my_custom_loop() { if( is_singular('state') && is_main_query() ) { $taxonomy = 'state_cat'; $terms = …
Category: Web

Set Microsoft Word links to open in new window/tab

I'm unable to set Word hyperlinks to open in a new window/tab. Basically, I create a Word document and paste its contents to WordPress, and everything is there, links do work, but they don't have "target=_blank" attribute added to them. I do set Target Frame option in Word, but nothing happens. I've tried using _blank and New Window values, but when looking at code the target attribute isn't added. I tried using Ctrl + F9 trick to force my links …
Category: Web

Remove Content Filter

I need help with removing the Content Filter from a Plugin: add_filter( 'the_content', array( &$this, 'addContentAds' ), 8 ); Do someone could help me please? Thank you and best regards
Category: Web

How can I extract the URL of a link from a post?

I am pretty new in WordPress and I have the following doubt. I have a page that take some informations from a list of post that belong to a specific category and show these informations into something like a "dashboard". So I have this code: <?php /** * The template for displaying all Parallax Templates. * * @package accesspress_parallax */ ?> <div class="service-listing clearfix"> <?php $args = array( 'cat' => $category, 'posts_per_page' => -1 ); $count_service = 0; $query = …
Category: Web

Execute Closing Shortcode After the_content

I need to execute a short code on thousands of posts which don't already contain the short code as i've added some manually. I'm using another function to add the opening short code after the 2nd paragraph which works. I've written this code which outputs the closing short code after the content but it does't execute. add_filter( 'the_content', 'closing_shortcode' ); function closing_shortcode( $content ) { if( !has_shortcode( $content, 'members') ) return $content; $close_shortcode = do_shortcode('[/member]'); return $content . $close_shortcode; } …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.