New answers tagged

0

I think a possible solution could be following codesnippet from Mark Kaplun. To solve issues with this you could remove the http part and Wordpress will/should use https instead. Because the rest of your website is working correctly I assume that further settings are correct and will do their job as wished. add_filter('the_content','wpse_217012',1000,1); ...


0

You can try get_pages like this way: <?php $args = array( 'child_of' => 'YOUR PAGE', 'parent' => 'YOUR PAGE', 'post_type' => 'attachment', 'post_status' => 'publish', 'numberposts' => -1 ); ?> NOTE: child_of Note that the child_of parameter will also fetch "grandchildren" of the given ...


0

The method I prefer to use is just a bit shorter then the previous answer. <php $myExcerpt = wp_trim_words( get_the_content(), 20, '' ) ; echo $myExcerpt ; ?> The WordPress function wp_trim_words() returns only text (no images). wp_trim_words ( string $text, int $num_words = 55, string $more = null )


0

I also needed to do this on a site recently. If you leave the title field empty then WordPress will replace the empty title with the name of the attachment during save. This is done by adding a function to the filter attachment_fields_to_save. If we unhook that filter the attachment can be saved with an empty title: // Remove WordPress built in filter that ...


0

A quick and easy way would be to just run a search on your Wordpress site on the name of the image. E.g. your-image.png. This should return a list of all the posts which have that image in it.


0

You can try the following function to insert image to a post. Note: The following function will not make the image "featured image". It will just uploaded the image and attach it to the post. It will return the attachment id if the upload is successful function insert_post_media( $post_id, $url){ $tmp = download_url( $url ); $file_array ...


3

For unattached images, the post_parent column in the wp_posts table, has the value of 0. Your gallery shortcode in that case is: [gallery id="0" columns="4"] which means you are calling get_children() with post_parent as 0. You can e.g. use the gallery shortcode callback gallery_shortcode() directly: if( $parent_id = $post->post_parent ) { echo ...



Top 50 recent answers are included