0
votes

I am trying to add alt tags to a custom boat carousel and boat page on my website. Not sure what PHP I need to add and where to put it. The images on both the carousel and the page are thumbnails.

I have boat_page.php and boat_carousel.php which is where I think the code needs to be added.

Not sure if I should add all the code to this post or not.

This is a link to the page https://www.embarkboathire.com.au/boats/

You can see the boats at the bottom there are 15 per page.

'', 'section_intro' => '', 'posts_per_page' => '12', 'order' => '', 'price_from' => '', 'price_to' => '', 'locations' => '', 'features' => '', 'options' => '', 'charter_lengths' => '', 'total_boat_capacity' => '', ), $atts ) ); $sc_att_order = $order; $sc_att_posts_per_page = $posts_per_page; $sc_att_price_from = $price_from; $sc_att_price_to = $price_to; $sc_att_charter_lengths = $charter_lengths; $sc_att_locations = $locations; $sc_att_features = $features; $sc_att_options = $options; $sc_filtered_boat_capacity = $total_boat_capacity; if ( $sc_att_order == 'newest' ) { $sc_att_order = 'DESC'; } elseif ( $sc_att_order == 'oldest' ) { $sc_att_order = 'ASC'; } else { $sc_att_order = 'DESC'; } $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; if( isset( $_GET['from'] ) && $_GET['from'] !== '' ) { $filtered_price_from = (int)$_GET['from']; } if( isset( $_GET['to'] ) && $_GET['to'] !== '' ) { $filtered_price_to = (int)$_GET['to']; } if( isset( $_GET['boat_capacity'] ) && $_GET['boat_capacity'] !== '' ) { $filtered_boat_capacity = (int)$_GET[ 'boat_capacity' ]; } if( isset( $_GET['buffet_dining_capacity'] ) && $_GET['buffet_dining_capacity'] !== '' ) { $filtered_buffet_dining_capacity = (int)$_GET['buffet_dining_capacity']; } if( isset( $_GET['cocktail_capacity'] ) && $_GET['cocktail_capacity'] !== '' ) { $filtered_cocktail_capacity = (int)$_GET['cocktail_capacity']; } if( isset( $_GET['formal_capacity'] ) && $_GET['formal_capacity'] !== '' ) { $filtered_formal_dining_capacity = (int)$_GET['formal_capacity']; } if( isset( $_GET['offshore_capacity'] ) && $_GET['offshore_capacity'] !== '' ) { $filtered_offshore_capacity = (int)$_GET['offshore_capacity']; } if( isset( $_GET['overnight_capacity'] ) && $_GET['overnight_capacity'] !== '' ) { $filtered_overnight_capacity = (int)$_GET['overnight_capacity']; } if( get_query_var( 'ycbe_locations' ) !== 'any' ) { $filtered_locations = get_query_var( 'ycbe_locations' ); } if( get_query_var( 'ycbe_features' ) !== 'any' ) { $filtered_features = get_query_var( 'ycbe_features' ); } if( get_query_var( 'ycbe_options' ) !== 'any' ) { $filtered_options = get_query_var( 'ycbe_options' ); } if( get_query_var( 'ycbe_charter_lengths' ) !== 'any' ) { $filtered_charter_lengths = get_query_var( 'ycbe_charter_lengths' ); } $meta_query = array( 'relation' => 'AND' ); $tax_query = array( 'relation' => 'AND' ); if( isset( $sc_att_price_from ) && $sc_att_price_from !== '' ) { $meta_query[] = array( 'key' => '_ycbe_price_from', 'value' => $sc_att_price_from, 'compare' => '>=', 'type' => 'DECIMAL', ); } else { if( isset( $filtered_price_from ) ) { $meta_query[] = array( 'key' => '_ycbe_price_from', 'value' => $filtered_price_from, 'compare' => '>=', 'type' => 'DECIMAL', ); } } if( isset( $sc_att_price_to ) && $sc_att_price_to !== '' ) { $meta_query[] = array( 'key' => '_ycbe_price_from', 'value' => $sc_att_price_to, 'compare' => '>=', 'type' => 'DECIMAL', ); } else { if( isset( $filtered_price_to ) ) { $meta_query[] = array( 'key' => '_ycbe_price_from', 'value' => $filtered_price_to, 'compare' => ' 'DECIMAL', ); } } if( isset( $sc_filtered_boat_capacity ) && $sc_filtered_boat_capacity != '' ) { $meta_query[] = array( 'key' => '_ycbe_boat_capacity', 'value' => $sc_filtered_boat_capacity, 'compare' => '>=', 'type' => 'DECIMAL', ); } if( isset( $filtered_buffet_dining_capacity ) ) { $meta_query[] = array( 'key' => '_ycbe_buffet_dining_capacity', 'value' => $filtered_buffet_dining_capacity, 'compare' => '>=', 'type' => 'DECIMAL', ); } if( isset( $filtered_cocktail_capacity ) ) { $meta_query[] = array( 'key' => '_ycbe_cocktail_capacity', 'value' => $filtered_cocktail_capacity, 'compare' => '>=', 'type' => 'DECIMAL', ); } if( isset( $filtered_formal_dining_capacity ) ) { $meta_query[] = array( 'key' => '_ycbe_formal_dining_capacity', 'value' => $filtered_formal_dining_capacity, 'compare' => '>=', 'type' => 'DECIMAL', ); } if( isset( $filtered_offshore_capacity ) ) { $meta_query[] = array( 'key' => '_ycbe_offshore_capacity', 'value' => $filtered_offshore_capacity, 'compare' => '>=', 'type' => 'DECIMAL', ); } if( isset( $filtered_overnight_capacity ) ) { $meta_query[] = array( 'key' => '_ycbe_overnight_capacity', 'value' => $filtered_offshore_capacity, 'compare' => '>=', 'type' => 'DECIMAL', ); } if( isset( $sc_att_locations ) && $sc_att_locations !== '' ) { $sc_att_locations = explode( '+', $sc_att_locations ); $tax_query_child = array(); foreach( $sc_att_locations as $sc_att_location ) { $tax_query_child[] = array( 'taxonomy' => 'ycbe_location', 'field' => 'slug', 'terms' => $sc_att_location, ); } $tax_query[] = array_merge( ['relation'=>'OR'], $tax_query_child ); } else { if( isset( $filtered_locations ) && $filtered_locations !== '' ) { $filtered_locations = explode( '+', $filtered_locations ); $tax_query_child = array(); foreach( $filtered_locations as $filtered_location ) { $tax_query_child[] = array( 'taxonomy' => 'ycbe_location', 'field' => 'slug', 'terms' => $filtered_location, ); } $tax_query[] = array_merge( ['relation'=>'OR'], $tax_query_child ); } } if( isset( $sc_att_features ) && $sc_att_features !== '' ) { $sc_att_features = explode( '+', $sc_att_features ); foreach( $sc_att_features as $sc_att_feature ) { $tax_query[] = array( 'taxonomy' => 'ycbe_feature', 'field' => 'slug', 'terms' => $sc_att_feature, ); } } else { if( isset( $filtered_features ) && $filtered_features !== '' ) { $filtered_features = explode( '+', $filtered_features ); foreach( $filtered_features as $filtered_feature ) { $tax_query[] = array( 'taxonomy' => 'ycbe_feature', 'field' => 'slug', 'terms' => $filtered_feature, ); } } } if( isset( $sc_att_options ) && $sc_att_options !== '' ) { $sc_att_options = explode( '+', $sc_att_options ); foreach( $sc_att_options as $sc_att_option ) { $tax_query[] = array( 'taxonomy' => 'ycbe_option', 'field' => 'slug', 'terms' => $sc_att_option, ); } } else { if( isset( $filtered_options ) && $filtered_options !== '' ) { $filtered_options = explode( '+', $filtered_options ); foreach( $filtered_options as $filtered_option ) { $tax_query[] = array( 'taxonomy' => 'ycbe_option', 'field' => 'slug', 'terms' => $filtered_option, ); } } } if( isset( $sc_att_charter_lengths ) && $sc_att_charter_lengths !== '' ) { $sc_att_charter_lengths = explode( '+', $sc_att_charter_lengths ); $tax_query_child = array(); foreach( $sc_att_charter_lengths as $sc_att_charter_length ) { $tax_query_child[] = array( 'relation' => 'OR', array ( 'taxonomy' => 'ycbe_charter_length', 'field' => 'slug', 'terms' => $filtered_charter_length, ), ); } $tax_query[] = array_merge( ['relation'=>'OR'], $tax_query_child ); } else { if( isset( $filtered_charter_lengths ) && $filtered_charter_lengths !== '' ) { $filtered_charter_lengths = explode( '+', $filtered_charter_lengths ); $tax_query_child = array(); foreach( $filtered_charter_lengths as $filtered_charter_length ) { $tax_query_child[] = array( 'taxonomy' => 'ycbe_charter_length', 'field' => 'slug', 'terms' => $filtered_charter_length, ); } $tax_query[] = array_merge( ['relation'=>'OR'], $tax_query_child ); } } $post_query = new WP_Query( array( 'post_type' => 'ycbe_boat', 'order' => $sc_att_order, 'posts_per_page' => $sc_att_posts_per_page, 'paged' => $paged, 'meta_query' => $meta_query, 'tax_query' => $tax_query, ) ); global $post; global $wp_query; ob_start(); ?>
<div class="our-yachts-sections">
    <div class="yacht-charter-carousel-wrapper">
        <h3 class="center-title"><?php echo $section_title; ?></h3>
        <div class="title-block2"></div>
        <p class="yacht-intro-text"><?php echo $section_intro; ?></p>
        <div class="owl-carousel1 yacht-block-wrapper">
            <?php if( isset( $order ) ) {
                if ( $order == 'oldest' ) {
                    $yacht_order = 'ASC';
                } else {
                    $yacht_order = 'DESC';
                }
            }
            $args = array(
                'post_type' => 'ycbe_boat',
                'posts_per_page' => $posts_per_page,
                'order' => $yacht_order
            );

            //$post_query = new WP_Query( $args );
            if( $post_query->have_posts() ) {
                while( $post_query->have_posts() ) {
                    $post_query->the_post(); ?>
                    <div class="yacht-block">
                <?php if( has_post_thumbnail() ) { ?>
                    <div class="yacht-block-image">
                        <?php $yacht_diff_days = yacht_diff_days( date( 'Y-m-d' ), get_the_time( 'Y-m-d' ) ); ?>
                        <?php if ( $yacht_diff_days < 20 ) { ?>
                            <div class="new-icon"><?php _e( 'New', 'yachtcharter' ); ?></div>
                        <?php }
                        $src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'medium' ); ?>
                        <a href="<?php echo the_permalink(); ?>"><img src="<?php echo $src[0]; ?>" /></a>
                    </div>
                <?php } ?>
                <div class="yacht-block-content">
                    <h3><a href="<?php echo the_permalink(); ?>"><?php the_title(); ?></a></h3>
                    <?php  echo '<p class="element-excerpt">' .  get_the_excerpt( get_the_ID()) . '</p>' ; ?>
                    <div class="title-block5"></div>
                    <?php
                    $main_feature_1 = get_post_meta( get_the_ID(), '_ycbe_boat_capacity', true );
                    $main_feature_2 = get_post_meta( get_the_ID(), '_ycbe_price_from', true );
                    $main_feature_3 = get_the_excerpt( get_the_ID());
                    if( $main_feature_1 || $main_feature_2 || $main_feature_3 ) { ?>
                        <ul>
                            <?php

                            if( $main_feature_1 ) { echo '<li>' . '<span class="element-capacity">' .'Total Capacity: <strong>' . get_post_meta( get_the_ID(), '_ycbe_boat_capacity', true ) . '</strong></span>' .'</li>'; }
                            if( $main_feature_2 ) { echo '<li>' . '<span class="element-price-from">' .'Price P/H From: <strong>$'. get_post_meta( get_the_ID(), '_ycbe_price_from', true ) . '</strong></span>' . '</li>'; }

                            ?>
                        </ul>
                    <?php }
                    $boatAddress =  "/boats/" . get_the_title();
                    $boatAddress = str_replace(" ","-", $boatAddress); ?>
                    <a class="seeMoreButton" href="<?php echo the_permalink(); ?>">See More</a>
                </div>
            </div>
                <?php }
            } ?>
        </div>
    </div>
</div>

<?php wp_reset_postdata();
return ob_get_clean();

}

add_shortcode( 'boat_carousel', 'ycbe_boat_carousel_shortcode' ); ?>

I hope i have done all that the way it should be.

Many thanks

Danny Kirk

1
please beautify your code before posting. we cannot understand your work hereahmednawazbutt
Hi not sure how to do that i copied the code from ATOM into the post above. When i try and add it again it says the code it to large. Thanks5 Star Cruises
This is link to all the code that can be downloaded. Hope that is allowed and good practise apologies if its not. dropbox.com/s/xsxype37cvp9fjy/boat_carousel.php?dl=0 Thanks Danny5 Star Cruises

1 Answers

0
votes

Change this line code:

<img src="<?php echo $src[0]; ?>" />

to:

<img src="<?php echo $src[0]; ?>" alt="<?php echo get_post_meta(get_post_thumbnail_id( $post->ID ), '_wp_attachment_image_alt', true); ?>" />