Featured video and image thumbnails from external links in Wordpress - wordpress

Is there a way to get a thumbnail from any website link? For example, if I take a link from imgur and post it on my website in the post itself, it shows the image. But when I go to the homepage of my website there is no featured image for that post. Just a great box. How could I generate a featured image of any link I posted from an external website?
I have used the video thumbnail plugin but it only works with certain websites.

try going into page.php of your theme, then search for the_post_thmbnail(). There add the image link
change this line:
<?php the_post_thumbnail(); ?>
to something like this:
<?php $name = get_post_meta($post->ID, 'ExternalUrl', true);
if( $name ) { ?>
<?php the_post_thumbnail(); ?>
<?php } else {
the_post_thumbnail();
} ?>
hope this helps :)

Related

Wordpress blog page featured image

I like to use the page's featured images in a background image in the header. When I add a new page and set the featured image, it appears as background image works exactly what I wanted. But on a Blog main page (the Home, page of displaying posts) I set the featured image and in the header display the first post's featured image insetad the one I set at the page's featured image. Tried to find solution, but nothing works, don't know how to magae it. Here is my code that handle background image:
<div class="sub-header"
<?php
if (has_post_thumbnail( $post->ID ) ):
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
echo 'style="background-image: url(\'';
echo $image[0];
echo '\');"';
endif;
?>
>
</div>
Make the custom image source, whether it's assigned in the customizer or hard coded.

Get attached file url from upload WCK Wordpress plugin custom field creator not an image type

How to get the attached file from WCK plugin in Wordpress eventhough it is not an image? like an audio file.
This is the code that I have tried and it works! :)
Below is just an example.
<?php
$wck_custom = get_post_meta( $post->ID, 'audiosamps', true);
foreach($wck_custom as $wck_cstm) {
$audio_file = $wck_cstm['audio_file'];
$src_audio_file = wp_get_attachment_url( $audio_file);
?>
<div class="audio-cont"><audio src="<?php echo $src_audio_file; ?>"></audio></div>
<?php } ?>
With the used of wp_get_attachment_url() function from Wordpress

Remove featured image in Post

I want to remove the featured image in post and page, but keep it as thumbnail so that the site look good! My site is a wordpress based site.
Here's an example post of the site: http://www.tradingspotsilver.com/build-mt4-custom-ea-indicator-forex-free/
You could see that the featured image is on top of the post and occupy a lot of space. I've tried to look at the theme source but no luck.
The link given in your question is a single post page, you look in to your theme's root folder and can find a file named single.php, in that file you may find something like this
// "custom_size" could be anything like "single_page_image"
if ( has_post_thumbnail() ) : the_post_thumbnail('custom_size');
This line of code is responsible for showing the big image. Just remove this line and your image will not show up. Also, you may check this answer for custom image sizing.
For page template, you may look for a file named page.php and look for the similar code.
you can use timthumb for resizing:
with the code here: { https://code.google.com/p/timthumb/source/browse/trunk/timthumb.php }
create a file named timthumb.php in your theme folder, and at the place of the featured image php script, type:
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
//the_post_thumbnail();
$url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>
<div class="img-hold"> <img src="<?php bloginfo('template_directory') ?>/timthumb.php?src=<?php echo $url; ?>&w=219&h=125" width="219" height="125" /></div>
<p><? }
echo $content;
?></p>
change the value of height and width as per your wish at &w=, &h= and also width= , height=
hope this helps
just remove the the_post_thumbnail code in the single.php and page.php or content.php.
this function use in wordpress for show featured so just remove or comment it.
check your single.php and content.php page to solve this problem its right there
if you dont require that code comment it / or modify it as you want.
dont mess things go easy with it or otherwise you will end up getting error
I had the same issue and i could not find any solution in single.php
Its simple although:
just comment:
from content.php page
This is for the Dazzle Theme
I found mine in "content-single.php and removed :
<?php the_post_thumbnail( 'dazzling-featured', array( 'class' => 'thumbnail' )); ?>
Picture was gone from post.
It is obviously varies depending on theme.
For theme Freemium you need to remove the following lines in wp-content/themes/freemium/single.php:
<?php $freemium_feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); if($freemium_feat_image!="") { ?>
<img src="<?php echo $freemium_feat_image; ?>" alt="Banner" class="img-responsive img-responsive-freemium" />
<?php } ?>

Wordpress the_content(); showing content and attachements

I am using wordpress 3.6 and advanced custom field plugin 4.2.1.
advanced custom field settings - https://dl.dropboxusercontent.com/u/15109395/q/acf-media.png
my post - https://dl.dropboxusercontent.com/u/15109395/q/page-content.png
my single page code
<section id="contentLeft" class="single">
<?php if ( have_posts() ) { the_post(); the_content(); }?>
</section>
Result - https://dl.dropboxusercontent.com/u/15109395/q/page-front.png
but , i don't want that attachment image on content area. my local installation have no problem. not showing attachments. but my live website showing attachment uploaded to that post.
how can i solve this issue? please help me. Thanks.
My problem solved with this solution. Thanks.
http://wordpress.org/support/topic/thumbnails-magically-appearing-on-all-pages
if you want remove images from all posts and pages, simple copy the following code into your theme functions.php
<?php
function remove_images( $content ) {
$postOutput = preg_replace('/<img[^>]+./','', $content);
return $postOutput;
}
add_filter( 'the_content', 'remove_images', 100 );
?>
it will remove the images wherever the_content() have images
else you need to include this function in specific page , put the following code
<?php remove_filter( 'the_content', 'remove_images' ); ?>

wordpress advance custom field plugin showing broken image?

I am using wordpress acf plugin to show some custom images with their description and some text. So first I just made the acf plugin fileds like this and assigned the page to the home page with the conditional tags Location-> Rules-> Page->is equal to-> Home
now when I made my content-page.php to show the image code like this
<?php
if( get_field('image') ):
?><img src="<?php the_field('image'); ?>" alt="" /><?php
endif;
?>
I am getting only a broken image. The firebug is showing image source like this
Kindly help me to solve this. I have already wasted one day behind it. So any help and suggestions will be really appreciable. Thanks
Here is the screen shot for my custom fields setup
Here is the firebug html code which is showing the image source
Had this problem too. This is what I came up with that works:
<?php if (get_field('staff_photo')) {
$imgarray = get_field( 'staff_photo' );
?>
<img src="<?php echo $imgarray['url'] ; ?>" alt="" class="staff-photo" />
<?php } ?>
So, what I did was put get_field('field_name') array into a variable, then took a WAG that the key was 'url', which it was. Seems like the ACF people need to update their documentation.
Hah! Discovered another way -- this way you can pick a size:
<?php
if ( get_field('staff_photo') ) {
$imgarray = get_field( 'staff_photo' );
$size = "thumbnail"; // (thumbnail, medium, large, full or custom size)
echo wp_get_attachment_image( $imgarray['id'], $size );
}
?>
For wp_get_attachemnt_image to work, you have to extract the image id, for which the key is, ta-da! 'id'.

Resources