Specify Image Width and Height being called by PHP file - php

I am trying to figure out where to specify the image size of the facebook.png, which is 24x24.
Below is the code, but I am not sure how to specify the size. I know how to do this in HTML, but not in PHP.
<?php if ( get_option('solostream_facebook_url') ) { ?>
<a title="<?php echo stripslashes(get_option('solostream_facebook_link_text')); ?>" rel="external" href="http://www.facebook.com/<?php echo stripslashes(get_option('solostream_facebook_url')); ?>"><img class="facebook-sub" src="<?php bloginfo('template_directory'); ?>/images/facebook.png" alt="<?php echo stripslashes(get_option('solostream_facebook_link_text')); ?>" align="top" /></a>
<?php } ?>

Add the height and width attributes to <img>. Check below code.
<?php if ( get_option( 'solostream_facebook_url') ) { ?>
<a title="<?php echo stripslashes(get_option('solostream_facebook_link_text')); ?>" rel="external" href="http://www.facebook.com/<?php echo stripslashes(get_option('solostream_facebook_url')); ?>"><img class="facebook-sub" src="<?php bloginfo('template_directory'); ?>/images/facebook.png" alt="<?php echo stripslashes(get_option('solostream_facebook_link_text')); ?>" align="top" height="24" width="24"/></a>
<?php } ?>

Are you tryying to get PHP to retrieve the width / height?
If so, the getimagesize() function will do this:
<?php if ( get_option('solostream_facebook_url') ) { ?>
list($width, $height, $type, $dims) = getimagesize("bloginfo('template_directory')/images/facebook.png");
<a title="<?php echo stripslashes(get_option('solostream_facebook_link_text')); ?>" rel="external" href="http://www.facebook.com/<?php echo stripslashes(get_option('solostream_facebook_url')); ?>"><img $dims class="facebook-sub" src="<?php bloginfo('template_directory'); ?>/images/facebook.png" alt="<?php echo stripslashes(get_option('solostream_facebook_link_text')); ?>" align="top" /></a>
<?php } ?>

Related

Different Logo for Different Pages

Trying to show a different logo for page ID 1111 with code snippet below. But it is showing both logos on every page. Not sure what I'm missing or doing wrong. This snippet is in my header.php theme file Wordpress.
<a title="<?php echo esc_attr(get_bloginfo('name')); ?>" href="<?php echo esc_url(home_url()); ?>">
<img src="<?php echo esc_url($log_url); ?>" alt="<?php echo esc_attr(get_bloginfo('name')); ?>" width="<?php echo sh_set( $logo_size, 0); ?>" height="<?php echo sh_set( $logo_size, 1); ?>" >
<?php if (is_page( 1111 )) ?>
<img src="https://teamambrose.realtor/wp-content/uploads/2018/04/favicon.ico.png" alt="<?php echo esc_attr(get_bloginfo('name')); ?>" width="<?php echo sh_set( $logo_size, 0); ?>" height="<?php echo sh_set( $logo_size, 1); ?>" >
</a>
This is what I added to above hoping to only show second image url on page 1111 only.
<?php if (is_page( 1111 )) ?>
<img src="https://teamambrose.realtor/wp-content/uploads/2018/04/favicon.ico.png" alt="<?php echo esc_attr(get_bloginfo('name')); ?>" width="<?php echo sh_set( $logo_size, 0); ?>" height="<?php echo sh_set( $logo_size, 1); ?>" >
The reason why both logos are being shown on every page is because you specified an if-condition but did nothing before you closed the php tag.
Therefore, your extra logo html is being treated as if you added an additional line of HTML code which results in it being shown as any other regular HTML element you have added.
You should add a : behind the if statement to indicate that the line after the if statement is grouped under that particular if statement.
E.g.
<?php if ( is_page ( 1111 ) ) : ?>
<!-- This will only be printed when page id is 1111. -->
<? endif; ?>
You will also have to make sure to end the if statement or all of the code below the if statement will be processed with that if condition.
If what you want to achieve is to show logo A on pages other than 1111 page and only show logo B on page 1111, this is what you should do.
<a title="<?php echo esc_attr(get_bloginfo('name')); ?>" href="<?php echo esc_url(home_url()); ?>">
<?php if ( is_page( 1111 ) ) : ?>
<img src="https://teamambrose.realtor/wp-content/uploads/2018/04/favicon.ico.png" alt="<?php echo esc_attr(get_bloginfo('name')); ?>" width="<?php echo sh_set( $logo_size, 0); ?>" height="<?php echo sh_set( $logo_size, 1); ?>" >
<?php else : ?>
<img src="<?php echo esc_url($log_url); ?>" alt="<?php echo esc_attr(get_bloginfo('name')); ?>" width="<?php echo sh_set( $logo_size, 0); ?>" height="<?php echo sh_set( $logo_size, 1); ?>" >
<?php endif; ?>
</a>

put default image if there is no image using ACF

I am using Wordpress ACF plugin and I have custom products section and I put a custom field for featured image and it's working perfect.
Now I want if there is no featured image inserted then show a default image, I am using the following code but its not working.
<? php
$category_image = get_field('fimage');
if ($category_image) {
$category_image_url = $category_image['sizes']['product-thumb'];
}
if ($category_image_url) { ?>
<img src="<?php echo esc_url( get_template_directory_uri() ); ?>/timthumb.php?src=<?php echo $category_image['url']; ?>&w=300&h=250&zc=0" alt="<?php echo $category_image['name']; ?>" title="<?php echo $category_image['name']; ?>">
} else($category_image_url) { ?>
<img src="http://www.staticwhich.co.uk/static/images/products/no-image/no-image-available.png" alt="<?php echo $category_image['name']; ?>" title="<?php echo $category_image['name']; ?>">
<? php } ?>
$category_image="";
$category_image_url="";
$category_image = get_field('fimage');
if($category_image){
$category_image_url = $category_image['sizes']['product-thumb'];
}
if($category_image_url) { ?>
<img src="<?php echo esc_url( get_template_directory_uri() ); ?>/timthumb.php?src=<?php echo $category_image['url']; ?>&w=300&h=250&zc=0" alt="<?php echo $category_image['name']; ?>" title="<?php echo $category_image['name']; ?>">
<?php
}
else { ?>
<img src="http://www.staticwhich.co.uk/static/images/products/no-image/no-image-available.png" alt="<?php echo $category_image['name']; ?>" title="<?php echo $category_image['name']; ?>">
<?php } ?>

URL redirection depending on logged in or not

I have a logo and I want it to redirect to a homepage when the user is logged in or to a register site when the user is not logged in.
Here is my code:
<strong class="logo">
<?php if (is_user_logged_in()) ?>
<a href="http://test/register/">
<?php else ?>
<a href="<?php echo home_url();?>">
<img id="logo_img" title="<?php bloginfo('name'); ?>" src="<?php echo $logo_path; ?>" alt="<?php bloginfo('name'); ?>">
I'm using Wordpress. It says unexpected "else".
You are not doing your if / else statements correctly:
<strong class="logo">
<?php if (is_user_logged_in()) { ?>
<a href="http://test/register/">
<?php } else { ?>
<a href="<?php echo home_url();?>">
<?php } ?>
<img id="logo_img" title="<?php bloginfo('name'); ?>" src="<?php echo $logo_path; ?>" alt="<?php bloginfo('name'); ?>">
if you want to use this in a way for no brackets you have to do something like this:
<strong class="logo">
<?php
if (is_user_logged_in())
echo '<a href="http://test/register/">';
else
echo '<a href="'.home_url().'">';
?>
<img id="logo_img" title="<?php bloginfo('name'); ?>" src="<?php echo $logo_path; ?>" alt="<?php bloginfo('name'); ?>">
<strong class="logo">
<?php
if (is_user_logged_in())
{
echo '<a href="http://demo.com/register-path/">';
}
else
{
echo '<a href="'.home_url().'">';
}
echo '<img src="logo-path.png"></a>';
?>
`

Wordpress - Custom Header

Im trying to get a custom header to my wordpress theme.
$args = array(
'width' => 1920,
'height' => 800,
'default-image' => get_template_directory_uri() . '/images/header.jpg',
'uploads' => true,
); add_theme_support( 'custom-header', $args );
Added that to my functions.php and want the default-image to be the image that show if its no image set in admin.
But it wont show anything. the "img src" is empty.
Tried to upload a image then it shows, what could be the problem?
<img src="<?php echo header_image(); ?>" height="<?php echo get_custom_header()->height; ?>" width="<?php echo get_custom_header()->width; ?>" alt="" />
Using that in my front-page.php (the width and height is set correctly).
I couldn't find anything wrong with your code. However you can try this below. It always works well for me.
<?php if (get_header_image()) { ?>
<img src="<?php header_image(); ?>" alt="<?php bloginfo('name'); ?>">
<?php } else { ?>
<img src="<?php echo get_template_directory_uri(); ?>/images/header.jpg" alt="<?php bloginfo('name'); ?>">
<?php } ?>
Try:
<img src="<?php echo( get_header_image() ); ?>" height="<?php echo get_custom_header()->height; ?>" width="<?php echo get_custom_header()->width; ?>" alt="" />

If no image, display text?

I'm having a problem finding a code that will display text (<?php bloginfo('name'); ?>) when no image has been defined in the img src= (<?php echo get_option('to_logo'); ?>). This works in Firefox, of course, as a simple alt tag. But doesn't cut it in all browsers.
<a class="logo" href="<?php echo get_option('home'); ?>" title="<?php bloginfo('name'); ?>">
<img src="<?php echo get_option('to_logo'); ?>" title="Logo" alt="Logo" />
</a>
Wouldn't it be simpler just to do something like:
<a class="logo" href="<?php echo get_option('home'); ?>" title="<?php bloginfo('name'); ?>">
<?php
if (get_option('to_logo') != '') {
?>
<img src="<?php echo get_option('to_logo'); ?>" title="Logo" alt="Logo" />
<?php
} else {
echo bloginfo('name');
}
?>
</a>
This looks like WordPress. You can try to first test the image source to see if it is empty:
<a class="logo" href="<?php echo get_option('home'); ?>" title="<?php bloginfo('name'); ?>">
<?=(get_option('to_logo')) ? '<img src="'.get_option('to_logo').'" title="Logo" alt="Logo" />' : 'The alternate text'; ?>
</a>
You can try this:
if (get_option('to_logo') == '') {
echo bloginfo('name');
} else {
echo get_option('to_logo');
}

Categories