How to add image alt text this code blog - wordpress

I have two code blogs
I want it to look like this:
How should the code blog be
Missing alt text
And width height value
remove url and wordpress url
Sample:
<img class="alignnone" title="Women" src="https://3.bp.blogspot.com/-cR_7KLccvBM/WJ7h-yanzRI/AAAAAAAA6ps/hIk6C6Ha0eQzwIUaFpgYEkA6sY1bheTnwCLcB/s1600/women.jpg" alt="beatiful women" width="650" height="350"
<meta itemprop="url" content="<?php if (function_exists('catch_that_image')) {echo catch_that_image(); }?>" />

If you want to display your image like the sample then wordpress has two function to use:
If you are wanting to get outside the loop then,
wp_get_attachment_image(get_post_thumbnail_id( $post->ID), 'thumbnail');
inside the loop
if ( has_post_thumbnail( 'thumbnail' ) ) {
the_post_thumbnail();
}
This will directly create as you sample code. Hope this will work for you
Thank You

Related

Wordpress ACF Plugin - wp_get_attachment_image function doesn't work with ACF Options Page?

I'm trying to get an image asset shown on the front-end using the wp_get_attachment_image WordPress function, but it doesn't seem to work with my options page on ACF.
Here is my code:
<?php
$image = get_field('logo', 'option');
$size = 'full'; // (thumbnail, medium, large, full or custom size)
if( $image ) {
echo wp_get_attachment_image( $image, $size );
}
?>
Which looks like this on the back-end:
The picture you see above is an options page in ACF and when I try to query that image into the wp_get_attachment_image function, it doesn't work. However, when I run this code:
<img data-src="<?php the_field('logo', 'option'); ?>" alt="footer logo" class="lazyload" />
which is within an image tag, it works just fine.
I copied and pasted what was shows on the ACF docs located here (Basic Display ID), but it's not showing the image on the front-end.
Anything I'm missing guys?
Thanks a lot!
Return value in field should be Image ID. See Screenshot
What is the return value type you used? Image Array, Image URL, Image ID
And you need to get a field like this:
get_field('logo'); why do you add option?
More info here:
https://www.advancedcustomfields.com/resources/image/
wp_get_attachment_image requires the first parameter to be an image ID. In your case, if you are seeing the image using the code <img data-src="<?php the_field('logo', 'option'); ?>" alt="footer logo" class="lazyload" /> then get_field('logo', 'option') is returning the url of the image.. not the ID which is what you need if you are using wp_get_attachment_image.
What you need to do is change the Return Value of your logo field to Image ID.
Then you might have to re upload the image.
And also change this code <img data-src="<?php the_field('logo', 'option'); ?>" alt="footer logo" class="lazyload" /> to <img data-src="<?php echo wp_get_attachment_url(get_field('logo', 'option')); ?>" alt="footer logo" class="lazyload" />
ACf plugin returns value as you have set the return type.
If you have sent the return type as Image array then :
$image[0] -> full or $image[0][$full] or $image[$full] depending on the number of image uploaded.
If you have set return type as Image url:
<img src="<?php $image; ?>"> would do the work.
If you are setting return type as Image Id:
$img2 = wp_get_attachment_image_src(get_post_thumbnail_id($image),
$full); echo $img2[0];
I guess above methods will surely help you out.
Thanks

How to display post title in Wordpress?

I'd like to generate the wordpress post title in the following javascript code: I'm placing this code under the content in my wordpress posts.
<script charset="utf-8" type="text/javascript">
document.write('\x3Cscript type="text/javascript" charset="utf-8" src="http://adn.ebay.com/cb?programId=1&campId=5337203820&toolId=10026&customId=posttop&keyword=**POST-TITLE**&width=728&height=90&font=1&textColor=000000&linkColor=0000AA&arrowColor=8BBC01&color1=709AEE&color2=[COLORTWO]&format=ImageLink&contentType=TEXT_AND_IMAGE&enableSearch=y&usePopularSearches=n&freeShipping=n&topRatedSeller=y&itemsWithPayPal=n&descriptionSearch=n&showKwCatLink=n&excludeCatId=&excludeKeyword=&catId=177913%2C179767%2C1059&disWithin=200&ctx=n&autoscroll=n&flashEnabled=' + isFlashEnabled + '&pageTitle=' + _epn__pageTitle + '&cachebuster=' + (Math.floor(Math.random() * 10000000 )) + '">\x3C/script>' );
The keyword= part of the script is where I need to generate the wordpress post title. I was trying keyword="<?php single_post_title(); ?>" but it doesn't generate the wordpress post title... not sure if I'm on the right track or not.
Any help would be appreciated. Please remember I'm a newbie. If I forgot to mention something please ask. I'll be quick to respond.
Thanks a lot!
inside your loop see if ( have_posts() ) and while, use this inside the while statement.
$title= get_the_title();
Now the variable is set, you can use it later unless it is overwritten.
in your js:
keyword="<?php echo $title; ?>"
There's a simple way to do it for blog posts and normal pages. Here it is:
<?php the_title(); ?>

Advanced Custom Fields/PHP issue

I apologize if this is answered elsewhere, but I'm having an issue with this ACF code here: http://goo.gl/9onrFN I want the client to be able to add a portfolio site link (if applicable) to the artist page and the link would say "View Artist's Website" and the link would take the user to the artist's site in a new window. How would I go about not making this text not visible, unless there was a url entered into the custom field on the post? Here's the code:
<p><?php the_field('contact_phone_number'); ?><br />
or <?php the_field('contact_email'); ?><br />
View Artist's Website</p>
Thanks in advance!
You can check if a ACF field is set with:
if(get_field('artist_website')) {
the_field('artist_website');
}
Using the_field will simple echo the contents of your field, whereas get_field will return the value which is a lot more helpful. For example you could write the above code as:
Note: get_field simple returns the value of the field, if you want to check if a valid url has been entered you will have to use a regular expression.
Below is your code with an if statement performing an empty field check:
<p>
<?php the_field('contact_phone_number'); ?><br />
or <?php the_field('contact_email'); ?>
<?php if(get_field('artist_website')) { ?>
<br />View Artist's Website
You may find your code easier to read by pre-setting your variables and including HTML in the echo:
<p>
<?php
$contact_phone_number = get_field('contact_phone_number');
$contact_email = get_field('contact_email');
$artist_website = get_field('artist_website');
echo "{$contact_phone_number}<br />";
echo "or <a href='mailto:{$contact_email}'>{$contact_email}</a><br/ >;
if($artist_website) {
echo "View <a href='{$artist_website}' target='_blank'>Artist's website</a>";
}
?>
</p>

How can i display permalink inside the excerpt paragraphs

im trying to show the permalink right inside/after the excerpt
the code that im using at a designated area in my theme is this
<div id="headline">
<?php the_excerpt(); echo ''; echo '[Read more...]'; echo '';?>
</div>
the result
<p>the excerpt here</p>
<a>permalink here</a>
how can i show the permalink inside the same paragraphs that the excerpt is displayed ?
<p> the_excerpt; <a>permalink</a> </p>
thanks all.
You can place the following code in the functions.php fule of your theme
function new_excerpt_more($more) {
global $post;
return '[Read more...]';
}
add_filter('excerpt_more', 'new_excerpt_more');
This codex entry has more details on how you can modify what the excerpt spits out : http://codex.wordpress.org/Function_Reference/the_excerpt
I tried the above solution but it didn't solve my problem, the A tag still showed outside the P tags. I solved my problem using get_the_excerpt(), which returned just the excerpt text without the P tags.
http://codex.wordpress.org/Function_Reference/get_the_excerpt

Wordpress: how to make a post template with a fix image placement?

I am building a simple WP theme, but now I am stuck. I need to add an image on a fixed place for post_template A and 2 images on post_template B
Like so:
title
img
date
content
title
img img
date
content
Is it possible to make a template and on the admin side have the corresponding # of upload fields?
You can do that with custom fields...
In the edit page view add a custom field called "img1" for instance and the value should be the image url.
Then in your template A file you can output the image with:
<?php
$myimage = get_post_meta($post->ID, 'img1', true);
if ($myimage) { ?>
<img src="<?php echo $myimage; ?>" />
<?php } ?>
And in template B you just do that 2 times ;)

Resources