admin管理员组文章数量:1122826
I am trying to get the alt to display as it is written within the media library, but the necessary code edit is beyond my comprehension. The code below was created to modify wooCommerce. The best I could do now is to narrow down here the edit needs to take place. This line is one that needs edited, but I am uncertain what to change:
if ($image) echo '<img src="' . esc_url($image) .'" alt="EDIT HERE:plugins>woocommerce-CJD">';
Any help showing me how to get the alt tag to display would be greatly appreciated! Thank you
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
add_action('after_setup_theme', 'WC_CJD_tweak_action_hooks');
function WC_CJD_tweak_action_hooks () {
// put sorting before category list
remove_action( 'woocommerce_after_shop_loop', 'woocommerce_catalog_ordering', 30 );
remove_action( 'woocommerce_after_shop_loop', 'woocommerce_result_count', 20 );
add_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
add_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );
}
// add breadcrumb
add_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 1 );
add_filter( 'woocommerce_breadcrumb_defaults', 'WC_CJD_modify_breadcrumb' );
function WC_CJD_modify_breadcrumb ($defaults) {
$defaults['delimiter'] = '';
return $defaults;
}
// add category header area with image
add_action('woocommerce_archive_description', 'WC_CJD_wrap_cat_descr_open', 2);
add_action('woocommerce_archive_description', 'WC_CJD_wrap_cat_descr_close', 99);
function WC_CJD_wrap_cat_descr_open () {
if (is_product_category()) {
global $wp_query;
$cat = $wp_query->get_queried_object();
$thumbnail_id = intval(get_woocommerce_term_meta($cat->term_id, 'thumbnail_id', true));
$image = wp_get_attachment_image_url($thumbnail_id, 'shop_catalog');
echo '<div class="cat-header">';
if ($image) echo '<img class="cat-header-bg" src="' . esc_url($image) . '" alt="" />';
echo '<div class="cat-header-content">';
echo '<div class="cat-header-text">';
echo '<h1> Wholesale ' . $cat->name . ' </h1>';
}
}
function WC_CJD_wrap_cat_descr_close () {
if (is_product_category()) {
global $wp_query;
$cat = $wp_query->get_queried_object();
$thumbnail_id = intval(get_woocommerce_term_meta($cat->term_id, 'thumbnail_id', true));
$image = wp_get_attachment_image_url($thumbnail_id, 'shop_catalog');
echo '</div>';
if ($image) echo '<img src="' . esc_url($image) .'" alt="EDIT HERE:plugins>woocommerce-CJD">';
echo '</div>';
echo '</div>';
}
}
I am trying to get the alt to display as it is written within the media library, but the necessary code edit is beyond my comprehension. The code below was created to modify wooCommerce. The best I could do now is to narrow down here the edit needs to take place. This line is one that needs edited, but I am uncertain what to change:
if ($image) echo '<img src="' . esc_url($image) .'" alt="EDIT HERE:plugins>woocommerce-CJD">';
Any help showing me how to get the alt tag to display would be greatly appreciated! Thank you
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
add_action('after_setup_theme', 'WC_CJD_tweak_action_hooks');
function WC_CJD_tweak_action_hooks () {
// put sorting before category list
remove_action( 'woocommerce_after_shop_loop', 'woocommerce_catalog_ordering', 30 );
remove_action( 'woocommerce_after_shop_loop', 'woocommerce_result_count', 20 );
add_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
add_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );
}
// add breadcrumb
add_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 1 );
add_filter( 'woocommerce_breadcrumb_defaults', 'WC_CJD_modify_breadcrumb' );
function WC_CJD_modify_breadcrumb ($defaults) {
$defaults['delimiter'] = '';
return $defaults;
}
// add category header area with image
add_action('woocommerce_archive_description', 'WC_CJD_wrap_cat_descr_open', 2);
add_action('woocommerce_archive_description', 'WC_CJD_wrap_cat_descr_close', 99);
function WC_CJD_wrap_cat_descr_open () {
if (is_product_category()) {
global $wp_query;
$cat = $wp_query->get_queried_object();
$thumbnail_id = intval(get_woocommerce_term_meta($cat->term_id, 'thumbnail_id', true));
$image = wp_get_attachment_image_url($thumbnail_id, 'shop_catalog');
echo '<div class="cat-header">';
if ($image) echo '<img class="cat-header-bg" src="' . esc_url($image) . '" alt="" />';
echo '<div class="cat-header-content">';
echo '<div class="cat-header-text">';
echo '<h1> Wholesale ' . $cat->name . ' </h1>';
}
}
function WC_CJD_wrap_cat_descr_close () {
if (is_product_category()) {
global $wp_query;
$cat = $wp_query->get_queried_object();
$thumbnail_id = intval(get_woocommerce_term_meta($cat->term_id, 'thumbnail_id', true));
$image = wp_get_attachment_image_url($thumbnail_id, 'shop_catalog');
echo '</div>';
if ($image) echo '<img src="' . esc_url($image) .'" alt="EDIT HERE:plugins>woocommerce-CJD">';
echo '</div>';
echo '</div>';
}
}
Share
Improve this question
asked Jun 23, 2017 at 12:50
Sean ManionSean Manion
113 bronze badges
1 Answer
Reset to default 1Something like this?
$image_alt = get_post_meta( $image->id, '_wp_attachment_image_alt', true);
To use in your string:
if ($image) echo '<img src="' . esc_url($image) .'" alt=".$image_alt.">woocommerce-CJD">';
Use it under the $image declaration. In your $image declaration make sure youll get the image attachment via wp_get_attachment_image() function.
本文标签: How can the alt be added to this wooCommerce category image
版权声明:本文标题:How can the alt be added to this wooCommerce category image? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736286724a1927726.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论