my theme is showing the alt text for the main header image as alt="". Even though I have added this in the media library etc.
I have found the PHP code in the header.PHP file as below. What do I need to change to manually put the alt text in?
<img class="logo" src="<?php echo esc_url(($site_logo)); ?>" alt="<?php bloginfo('sitename'); ?>" />
Thanks
You can't use sitename in <?php bloginfo('sitename'); ?> for example you can use <?php bloginfo( 'name' ); ?>
Below values what you can use.
https://developer.wordpress.org/reference/functions/bloginfo/#possible-values-for-show
Related
I have ACF set up in WP with a Gallery field. Currently I am displaying my images as follows:
<p><?php echo get_the_content(); ?></p>
<?php $images = get_field('gallery_images');
if( $images ): ?>
<div>
<ul>
<?php foreach( $images as $image ): ?>
<li class="portrait float">
<img src="<?php echo $image['url']; ?>" />
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif;
?>
I have also installed the Simple Lightbox Plugin but have been unsuccessful so far. How do I add the URL link of my ACF Gallery images. I have tried wrapping my image tag in a link tag with rel="lightbox" and several other variations including:
<img rel="lightbox[gallery_images] src="<?php echo $image['url']; ?>" />
Is there any way I can enable Attachment Display Settings for my ACF Gallery images in my WP post. I think this might be handy to have?
Any help is much appreciated :)
I used the following which worked.
<img rel="lightbox[gallery_images]" src="<?php echo $image['url']; ?>" />
All my images are full size so didn't need the following at all:
echo $image_large[0];
I am just learning Drupal and I am having trouble to display a logo on my custom theme..
page.tpl.php:
<a href="<?php print $front_page;?>">
<img src="/<?php print $directory;?>/img/logo.png" alt="<?php print $site_name;?>" height="80"
width="150" />
</a>
As I look inspecter, I see that the path is correct:
<img src="/themes/bony/img/logo.png" alt="Haldun Atar Drupal Page" height="80" width="150">
On Appearance > Settings panel I also entered the path: themes/bony/img/logo.png
I just can't display the logo.. Where do I search the problem?
P.s: I have the logo img in img file.
Thank you in advance!
If you uploaded the file on the theme settings page, you should have a $logo variable in the page.tpl.php (though this will depend on if you have overridden the preprocess).
You can see how it is output if you look in the 'modules/system/page.tpl.php'.
In the system page.tpl.php it is output like this:
<?php if ($logo): ?>
<a href="<?php print $front_page; ?>" title="<?php print t('Home'); ?>" rel="home" id="logo">
<img src="<?php print $logo; ?>" alt="<?php print t('Home'); ?>" />
</a>
<?php endif; ?>
If you click on the src link in inspector does it take you to the image? If not try an absolute path like /<absolute>/<path>/<to>/<your>/<folder>.
Did you clear cache after you made the changes?
Admin -> configuration -> performance -> clear cache
I need an image to be appeared next to Add to Cart button in WooCommerce product page, using Advanced Custom Fields plugin. In order to displaying values, as I know, the_field function must be added to some page template. In Which template file and where should I place the the_field function?
It depends on what type of "add to cart" you are using (simple product, variable, etc).
Regardless, each are in this directory (for single-product): templates/single-product/add-to-cart.
You should (for best results) use the image array for your ACF content.
You would write this (changing the get_field('image') to get_field('your_field_name'):
<?php
$image = get_field('image'); // assigns the image field to the variable of $image
if( !empty($image) ): ?> <!--if the $image variable isn't empty, display the following:-->
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" /> <!--displays the URL for the image variable and also the alt tag which is entered in the WordPress media library-->
<?php endif; ?> <!--ends the if statement -->
If you wanted a basic display, you could use image URL and do this:
<?php if( get_field('image') ): ?> <!--only shows the image field if it exists (an image was uploaded through ACF)-->
<img src="<?php the_field('image'); ?>" /> <!--displays the URL of the image if it is not an array/ID set in ACF field parameters, but a URL -->
<?php endif; ?> <!-- end the IF statement -->
I prefer using the alt tag when at all possible.
Our web site is using the theme's slider.php on our front page. I'd like for the images displayed in that slider to use the alt text that is in the post meta (edited in the WP media library).
I've attempted to create a variable ($alt), and have that variable echoed when the img is called, but is coming up empty. Here's the relevant portion of slider.php:
$alt = get_post_meta($post->ID, '_wp_attachment_image_alt', true);
<img src="<?php echo $thumbnail[0]; ?>" alt="<?php echo $alt[0]; ?>" />
</a>
<?php else: ?>
`
Any idea what I'm doing wrong?
You have set the third argument as true which means the function get_post_meta returns a string;
http://codex.wordpress.org/Function_Reference/get_post_meta
Therefore the following should work instead;
<img src="<?php echo $thumbnail[0]; ?>" alt="<?php echo $alt; ?>" />
Okay - so I've figured this out. The code above is trying to get the post meta from the thumbnail of the image - and, to my knowledge, the thumbnail image doesn't have meta data.
I've just created a custom field, and now the slider loop call thats field.
I am using the ACF purely so the user can upload images to a predefined location and have assigned the page rules accordingly. Everything seems to be fine on the WP back-end, with the three images uploaded to the fields. However, on the font end, nothing apart from blank box is appearing at all where the images should be. Looking at the source that WP is outputting, there is only blank code:
<img src="" class="middle" alt="image1"/>
This is the loop I am using:
<?php query_posts("posts_per_page=1&post_type=page&page_id=168"); if (have_posts()) :
while ( have_posts() ) :
the_post(); ?>
<!--If you want to refer to the child of parent page, use "post_parent=" -->
<li>
<h3><?php the_title(); ?></h3>
<?php the_excerpt(); ?>
<img src="<?php the_field('image_1'); ?>" class="middle" alt="image1"/>
View More
</li>
<?php endwhile; ?>
<!-- post navigation -->
<?php else: ?>
<!-- no posts found -->
<?php endif; ?>
<?php wp_reset_query(); ?>
It is important to note that I am not pulling the images from another page. I just want the images to relate to the template & page I am working on.
Make sure the image field is outputting the id or url of the image link.
<?php if(get_field('YOUR FIELD NAME')): while(has_sub_field('YOUR FIELD NAME')): ?>
<img class="logo" src="<?php the_sub_field('image_1'); ?>" />
<?php endwhile; endif; ?>
I just needed to nominate the home page id the function:
<img src="<?php the_field('image_2', '245'); ?>" class="middle" alt="image2"/>
you can use get_the_field() to get the right value of the field,
<img src="<?php get_the_field('image_1'); ?>" class="middle" alt="image1"/>