So I am using Wordpress and I have to have a specific logo on a specific page. From research I have to use conditional logic to swap the existing logo with another depending on the current page. Everything I have tried seems to just break the theme.. Any help on guiding me in the correct direction? So basically every page except page_id=79 would have the same logo in the header.
<a id="logo" href="<?php echo home_url(); ?>">
<?php
if(!empty($options['use-logo'])) {
$default_logo_id = (!empty($options['retina-logo'])) ? 'id="default-logo"' : null;
echo '<img '.$default_logo_id.' alt="'. get_bloginfo('name') .'" src="' . $options['logo'] . '" />';
if(!empty($options['retina-logo'])) echo '<img id="retina-logo" alt="'. get_bloginfo('name') .'" src="' . $options['retina-logo'] . '" />';
} else { echo get_bloginfo('name'); }
?>
</a>
<?php if ( is_page(79) ) { ?>
What to displayed on page 79.
<?php } else { ?>
What will be displayed everywhere else.
<?php } ?>
This should work.
Try using get_queried_object_id();
<a id="logo" href="<?php echo home_url(); ?>">
<?php
if(!empty($options['use-logo']) && get_queried_object_id() != 79) {
$default_logo_id = (!empty($options['retina-logo'])) ? 'id="default-logo"' : null;
echo '<img '.$default_logo_id.' alt="'. get_bloginfo('name') .'" src="' . $options['logo'] . '" />';
if(!empty($options['retina-logo'])) echo '<img id="retina-logo" alt="'. get_bloginfo('name') .'" src="' . $options['retina-logo'] . '" />';
} else { echo get_bloginfo('name'); }
?>
</a>
The url of your logo image is contained within $options['logo']. You should be able to modify this in the admin section of your WordPress installation (try looking in "Appearance -> Header").
Related
I have a website where users may upload images...
I need to add my logo (watermark) to the images every single time to uploaded.
How can I do so?
Anybody have a good tutorial, article or example for this? Or know of any function in php which I would need to find the position of the watermark?
<?php
if(houzez_edit_property()) {
$property_images = get_post_meta( $property_data->ID, 'fave_property_images', false );
$featured_image_id = get_post_thumbnail_id( $property_data->ID );
$property_images[] = $featured_image_id;
$property_images = array_unique($property_images);
if (!empty($property_images[0])) {
foreach ($property_images as $prop_image_id) {
$is_featured_image = ($featured_image_id == $prop_image_id);
$featured_icon = ($is_featured_image) ? 'text-success' : '';
$img_available = wp_get_attachment_image($prop_image_id, 'thumbnail');
if (!empty($img_available)) {
echo '<div class="col-md-3 col-sm-4 col-6 property-thumb">';
echo wp_get_attachment_image($prop_image_id, 'houzez-item-image-1', false, array('class' => 'img-fluid'));
echo '<div class="upload-gallery-thumb-buttons">';
echo '<button class="icon icon-fav icon-featured" data-property-id="' . intval($property_data->ID) . '" data-attachment-id="' . intval($prop_image_id) . '"><i class="houzez-icon icon-rating-star full-star '.esc_attr($featured_icon).'"></i></button>';
echo '<button class="icon icon-delete" data-property-id="' . intval($property_data->ID) . '" data-attachment-id="' . intval($prop_image_id) . '"><span class="btn-loader houzez-loader-js"></span><i class="houzez-icon icon-remove-circle"></i></button>';
echo '</div>';
echo '<input type="hidden" class="propperty-image-id" name="propperty_image_ids[]" value="' . intval($prop_image_id) . '"/>';
if ($is_featured_image) {
echo '<input type="hidden" class="featured_image_id" name="featured_image_id" value="' . intval($prop_image_id) . '">';
}
echo '</div>';
}
}
}
}
?>
Use PHP GD Library. You can open saved image file, write text or overlay watermark image and save image again.
add_filter('wp_nav_menu_objects', 'my_wp_nav_menu_objects', 10, 2);
function my_wp_nav_menu_objects( $items, $args ) {
// loop
foreach( $items as &$item ) {
// vars
$image = get_field('menu_item_image', $item);
// append image
if( $image ) {
$item->title .= '<img class="ttl" src="' . <?php echo
$image['url']; ?> . '" alt="' . <?php echo $image['alt']; ?> . '" />';
}
}
// return
return $items;
}
What am I doing wrong? New to PHP and WordPress functions. The problem seems to be in the append image section.
replace this:
$item->title .= '<img class="ttl" src="' . <?php echo
$image['url']; ?> . '" alt="' . <?php echo $image['alt']; ?> . '" />';
for this
$item->title .= '<img class="ttl" src="' .$image['url']. '" alt="' . $image['alt'] . '" />';
you cannot use this <?php echo $image['alt']; ?> inside echo '...'
Reference: http://php.net/manual/en/function.echo.php
I am using AFC Pro and created an options pafe so tjhat the user can upload a new header logo whenever he wants to.
The ACF field is called "headerlogo".
What I want now is that the Logo gets replaced by my theme automatically.
My Variables are:
$headerlogo = wp_get_attachment_image_src(get_field('headerlogo', 'option'), 'full');
$default_logo = '<img src="'echo .$headerlogo[0].'" alt="SITE Logo">';
they get called in:
echo '<a href="'. esc_url( home_url( '/' ) ) .'">
' . $default_logo . '
</a>';
But the Output is:
<a href="http://www.xxx.de/">
<img src="" alt="SITELogo">
</a>
What am I doing wrong here?
Thank in advance.
This should work:
<?php
$headerlogo = get_field('headerlogo');
if( !empty($headerlogo) ):
$default_logo = '<img src="'. $headerlogo['url'] . '" alt="' . $headerlogo['alt'] . '" />';
endif;
echo '' . $default_logo . '';
?>
I am trying to have multiple lines of pictures with 6 pics in each line. Currently there are 4 pics on each line and I am not sure how to make it so I have 6. Any help would be very appreciated!
Here is my code:
<?php
$pageTitle = "Bright Punch Love";
$section = "home";
include('inc/products.php');
?>
<?php include('inc/header.php'); ?>
<div id="top"><img src="top.png" width="1337"></div>
<div class="shirts">
<ul class= "shirts-section">
<?php
foreach($products as $product_id => $product) {
echo "<li>";
echo '<a href="shirt.php?id=' . $product_id . '">';
echo '<img src="' . $product["img"] . '" width= 200 alt="' . $product["name"] . '">';
echo '<p id="details">$30 View Details</p>';
echo "</a>";
echo "</li>";
}
?>
</ul>
</div>
<?php include('inc/footer.php'); ?>
<div id="bottom-index"><img src="bottom-index.png" width="1337"></div>
I would suggest to use % instead of px. Also you use the width tag. Try to avoid using css in your html code. Use class="..." instead and include your css file in the head tag. I make the file now in the head, because it is easier for you. But I would recommend to make an file just for the css.
<head>
<style type="text/css">
.picture{
width : 15%;
}
</style>
</head>
echo '<img src="' . $product["img"] . '" class=\"picture\" alt="' . $product["name"] . '">';
Use PHP's array_chunk function to short your answer. Just Try.
$products_new = array_chunk($products, 6);
foreach($products_new as $product_id => $product) {
//Your code
}
I'm using a PHP code on my wesbiste to get thumbnails of vimeo videos.
here is the code :
<?php
echo '<img src="' . get_vimeo_thumb('43096888', 'thumbnail_large') . '" class="image_page_texte_et_medias" style="cursor:pointer" >';
?>
I'm using a ACF custom field with the video ID
<?php the_sub_field('vimeo'); ?>
What I'm trying to do is to replace the ID in my first php code ('43096888') by :
<?php the_sub_field('vimeo'); ?>
can anybody help me with this,
thanks a lot,
aren't you allowed to use variables as arguments? something like:
<?php
$foo = the_sub_field('vimeo');
echo '<img src="' . get_vimeo_thumb($foo, 'thumbnail_large') . '" class="image_page_texte_et_medias" style="cursor:pointer" >';
?>
<?php
echo '<img src="' . get_vimeo_thumb(the_sub_field('vimeo'), 'thumbnail_large') . '" class="image_page_texte_et_medias" style="cursor:pointer" >';
?>
<?php
echo '<img src="' . get_vimeo_thumb(the_sub_field('vimeo'), 'thumbnail_large') . '" class="image_page_texte_et_medias" style="cursor:pointer" >';
?>
You can simply replace the string '43096888' with your function the_sub_field('vimeo') if that's something what you want.