Fixing WordPress Header - php

I was provided this bit of code to add to my functions.php file by the support team of the company from whom I bought the theme.
I wanted my logo and site name side by side and they gave me this code:
function igthemes_site_logo() {
$custom_logo_id = get_theme_mod( 'custom_logo' );
$image = wp_get_attachment_image_src( $custom_logo_id , 'full' );
$url = home_url( '/' );
echo '<a href="' . esc_url( $url ) .'">';
echo "<img class='logo' src= " . $image[0] . " style='float:left; padding:15px;'>";
echo '<div style="float:left; padding:15px 0;">' . get_bloginfo( 'title' ) . '</div>';
echo '</a>';
}
However, that made it look like this.Two logos and titles
What do I change to just show one logo and one title?

it seems like that php function (igthemes_site_logo()) is called twice. That would be in the PHP code, not in the code you posted which only contains the function itself.

Related

Wordpress: adding ‘srcset’ and ‘sizes’ attributes to image from customizer

Wordpress automatically adds srcset and sizes attributes to all images coming from posts. That’s very neat.
But how to I get WordPress to add those attributes to images that come from a customizer input?
In my case: a default image for posts. That default image is displayed when no image was uploaded in a post. It’s uploaded by the user through the customizer and called using get_theme_mod.
image from post (works fine, all attributes are added):
get_the_post_thumbnail($post->ID, 'news', array('class' => 'img-responsive'));
if no image is provided: the default image is loaded (no ’scrset’ and ’sizes’)
'<img src="' . esc_url( get_theme_mod( 'default_image' ) ) . '" alt="default image" class="img-responsive" />'
wp_image_add_srcset_and_sizes() seems to be the way to go but it requires attributes I don’t know where to get.
Thank you for your help!
this function does the trick:
function create_responsive_image( $img ) {
$img_id = attachment_url_to_postid( $img );
$img_srcset = wp_get_attachment_image_srcset( $img_id );
$img_sizes = wp_get_attachment_image_sizes( $img_id );
return '<img src="' . $img . '" srcset="' . esc_attr( $img_srcset ) . '" sizes="' . esc_attr( $img_sizes ) . '">';
}

Wordpress: Change Post Featured Image alt tags to the given alt tag while uploading

I am giving alt tags for an image while uploading, but it is not taking the given image alt tags , it shows blank
i tried to add this filter but still not working
/* Register callback function for post_thumbnail_html filter hook */
add_filter( 'post_thumbnail_html', 'meks_post_thumbnail_alt_change', 10, 5 );
/* Function which will replace alt atribute to post title */
function meks_post_thumbnail_alt_change( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
$post_title = get_the_title();
$html = preg_replace( '/(alt=")(.*?)(")/i', '$1'.esc_attr( $post_title ).'$3', $html );
return $html;
}
The post content is displayed from loop-single.php file
<div class="entry-content">
<?php the_content(); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
</div><!-- .entry-content -->
How to use those alt tags for my post featured image
Try this it worked for me :)
function change_post_thumbnail_html($html, $post_id, $post_thumbnail_id, $size, $attr) {
$id = get_post_thumbnail_id();
$src = wp_get_attachment_image_src($id, $size);
$alt = get_the_title($id); // gets the post thumbnail title
$class = $attr['class'];
$html = '<img src="' . $src[0] . '" alt="' . $alt . '" class="' . $class . '" />';
return $html;
}
add_filter('post_thumbnail_html', 'change_post_thumbnail_html', 99, 5);
Well i found out the error , it seems previous developer added the image manually to the post and featured image was also set . so i got confused.
i simply put the alt text in edit mode of the post directly.

Removing The IMG SRC tag in Wordpress

I'm trying to remove the "img src" tag from the php so it'll simply display the images url, rather than displaying the actual image. This is the code I've got so far and it works perfectly, but when it's rendered it shows thumbnails instead of urls.
<?php $pics = get_post_meta( $post->ID, 'pics', true );
foreach( $pics as $pics)
{
$image_attributes = wp_get_attachment_image_src( $pics['pictures'] );
echo '<img src="' . $image_attributes[0] . '" />';
}
?>
I know theres a way to do this, but I don't know how to remove the tags without breaking the image code. Any help is appreciated.
If you just want to echo the image src and not display it as an image then change
echo '<img src="' . $image_attributes[0] . '" />';
to
echo $image_attributes[0];
<?php
$pics = get_post_meta( $post->ID, 'pics', true );
foreach( $pics as $pics)
{
$image_attributes = wp_get_attachment_image_src( $pics['pictures'] );
echo $image_attributes[0];
}
?>
So do you want to show on the page the "html code" with the tag and the src attribute?
Have you tried to enclose "img" tag within "pre" tag?
echo '<pre><img src="' . $image_attributes[0] . '" /></pre>';

Need Proper Syntax for Condition (wrap Image with link only when there is one)

we had a developer code something for a Custom Post Type in WordPress that we need to tweak just a touch. They're not available right now, but I think it's a pretty simple PHP issue if knowing the proper syntax. Unfortunately, I'm not completely PHP fluent, so hoping to get some help.
We have a posts landing page where we are just displaying a post thumbnail if there is one, and a link to the full post page (single) ONLY if an email address has been entered into the custom post type. If no email address was entered for the post, no link to the final post. Here's the main chunk of code that is currently working properly for this:
$team_query = new WP_Query($args);
while ($team_query->have_posts()) {
$team_query->the_post();
$member_email = get_post_meta(
get_the_ID(), '_base_team_email', true
);
$html .= '<div class="span-6 team-member">';
if (has_post_thumbnail()) {
$html .= '<div class="member-photo-wrap">'
. get_the_post_thumbnail(get_the_ID(), 'medium')
. '</div>';
}
if (!empty($member_email)) {
$html .= '<p class="member-email">'
. '<a class="linkIcon" href="' . get_permalink() . '#member-top">'
. 'Email & Bio »'
. '</a></p>';
}
$html .= '</div>';
}
All we need to do is tweak so that IF an email address has been entered, the same hyperlink is added around the thumbnail image so it can link to the final post along with the 'Email & Bio' text link. But if NO email address is found, the thumbnail image displays as-is (e.g, no link added).
THANKS!
This would add a link to the thumbnail as well, if the $member_email is not empty.
$team_query = new WP_Query($args);
while ($team_query->have_posts()) {
$team_query->the_post();
$member_email = get_post_meta(
get_the_ID(), '_base_team_email', true
);
// Create anchor tag to use when member email is not empty
$memberEmailAnchorStart = '';
$memberEmailAnchorEnd = '';
if (!empty($member_email)) {
$memberEmailAnchorStart =
'<a class="linkIcon" href="' . get_permalink() . '#member-top">';
$memberEmailAnchorEnd = '</a>';
}
$html .= '<div class="span-6 team-member">';
if (has_post_thumbnail()) {
$html .= '<div class="member-photo-wrap">'
. $memberEmailAnchorStart
. get_the_post_thumbnail(get_the_ID(), 'medium')
. $memberEmailAnchorEnd
. '</div>';
}
if (!empty($member_email)) {
$html .= '<p class="member-email">'
. $memberEmailAnchorStart
. 'Email & Bio »'
. $memberEmailAnchorEnd
. '</p>';
}
$html .= '</div>';
}
Depending on what the linkIcon class does, you might want to remove it from the thumbnail anchor tag.

outputting a featured image rather than a link to a featured image

In the past, I used this custom function to create an image carousel on my WordPress blog with Thesis theme
function top_carousel() {
echo '<div id="topcarousel">';
$the_query = new WP_Query(array(
'category_name'=>'featured',
'orderby'=>'date',
'order'=>'DESC',
'showposts'=>'4'
));
while ($the_query->have_posts()) : $the_query->the_post();
$do_not_duplicate = $post->ID;
$post_image = thesis_post_image_info('thumb');
echo '<div class="carouselu">';
echo '' . $post_image['output'] . '<br />' . get_the_title() . '';
echo '</div>';
echo '<div style="clear:both"></div>';
echo '</div>';
}
add_action('thesis_hook_before_content_box', 'top_carousel');
It has been a while since I used the code, and, having recently setup a new WordPress blog, I discovered it doesn't work anymore, in that the image isn't getting displayed with the link to the post.
Someone suggested to me that this might be because I'm using featured images in my new WordPress blog. Following that tip and looking at the code on the WordPress code, I changed part of the custom function above to look like this
$post_image = wp_get_attachment_image_src( get_post_thumbnail_id(), 'small');
echo '<div class="carouselu">';
echo '' . $post_image[0] . '<br />' . get_the_title() . '';
echo '</div>';
This results in a little progress. Now a link to the image appears above the headline, rather than the actual image. For example,
http://localhost:8888/wp-content/uploads/2013/12/Screen-Shot-2013-12-27-at-9.37.49-AM.png
How do I get the image to show, rather than just a link to where the image is uploaded?
Update
Using the first answer to this post, I tried this code unsuccessfully
$post_image = get_the_post_thumbnail($post_id, 'small');
echo '<div class="carouselu">';
echo '' . $post_image['output'] . '<br />' . get_the_title() . '';
echo '</div>';
I also tried this unsuccessfully
$post_image = wp_get_attachment_image_src( get_the_post_thumbnail($post_id, 'small'));
echo '<div class="carouselu">';
echo '' . $post_image['output'] . '<br />' . get_the_title() . '';
echo '</div>';
Neither of those solutions output anything, whereas my attempt at least output a link to the uploaded image. Am I using the function incorrectly?
You should use the function get_the_post_thumbnail, refering to the doc : http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
Usage:
<?php echo get_the_post_thumbnail( $post_id, $size, $attr ); ?>
To enable Post Thumbnails, the current theme must include
add_theme_support( 'post-thumbnails' ); in its functions.php file

Categories