Display an Amazon Element without the CSS wrapper?
-
I’d like to display just the ListPrice and am using the amazon-element shortcode. Is there a way to have it output plain text rather than wrapping the price with amazon-element-wrapper class?
https://ww.wp.xz.cn/plugins/amazon-product-in-a-post-plugin/
-
Hi talkstory,
Sorry about the late response.You can get the following elements/fields without a wrapper using these fields in the shortcode:
title_clean desc_clean description_clean price_clean new-price_clean new price_clean image_clean med-image_clean sm-image_clean lg-image_clean full-image_clean large-image-link_clean features_clean link_clean button_clean customerreviews_cleanAdditionally, for any other field not listed, you can add
_cleanto the end of it and it will only return the element and not the wrapper with the element.Hope this helps!
Warm regards,
DonI’m trying the _clean shortcode, but a wrapper is still being applied. For example, I want the item URL so that I can create my own styled link.
I want a link that looks like this:
<a href="URL">PRICE</a>But if I use the _clean shortcakes, I end up with this:
<a href="<div class="amazon-element-wrapper">URL</div>"> <div class="amazon-element-wrapper">PRICE</div> </a>Can you post a sample shortcode you are using?
I will use it to check and see if I can some up with a reason/fix.Warm regards,
DonI’m using the shortcode within another plugin so that I can create my own function that combines output from custom fields which grab the author’s custom title and description with output from your plugin and wrap it up in a styled box.
Here is the portion of the code for creating the button
<a href="[amazon-element asin='B000I2PONS' fields='url_clean']"> <button>[amazon-element asin='B000I2PONS' fields='price_clean']</button> </a>And here is the resulting output HTML:
<a href="<div class='amazon-element-wrapper'> </div>"> <button> <div class="amazon-element-wrapper">$29.00 USD - In Stock</div> </button> </a>Hi Don,
Did you have any luck investigating the shortcode I added above?Sorry talkstory, I did, but I think I forgot to respond to the thread because I had marked it resolved initially.
I believe it is being cause by the editor because the shortcode is inside of the anchor tag.
I just put this back in my queue. I will try to see if I can come up with a filter or something that will fix it for you.
I will let you know in the next day or two at most.
Warm regards,
DonSome backstory –
WordPress removed the ability to add shortcodes to links (and any tag attribute) in version 4.2.3 (I believe), for security reasons. So using it like that is no longer an option.This is what you need to do (a two-part process):
- Add this filter/function to your theme’s
functions.phpfile after the php opening tag<?phpand before the php closing tag?>(if there is any):/** * Bypass the current value of shortcode value wieh certain conditions apply. * * @param array $retarr Items from shortcode (already processed). * @return array $retarr Corrected/adjusted Items */ function amazon_fix_my_own_shortcodes( $retarr ){ if( is_array( $retarr ) && !empty( $retarr ) ){ foreach( $retarr as $key => $val ){ if( isset( $retarr[ $key ][ 'link_clean' ] ) && isset( $retarr[ $key ][ 'price_clean' ] ) ){ $retarr[ $key ][ 'link_clean' ] = '<a href="' . $retarr[ $key ][ 'link_clean' ] . '"><button>' . $retarr[ $key ][ 'price_clean' ] . '</button></a>'; unset( $retarr[ $key ][ 'price_clean' ] ); } } } return $retarr; } // below filer checks our shortcode array and adjusts it based on our new needs. add_filter( 'amazon_product_in_a_post_plugin_elements_filter', 'amazon_fix_my_own_shortcodes' ); - Now adjust your shortcodes to be like this:
[amazon-element asin="B000I2PONS" fields="link_clean,price_clean" container=""]
Explanation – This adds a filter to WordPress that will alter the output of the plugin shortcode when both
'link_clean'AND'price_clean'fields are present in the shortcode. Additionally, addingcontainer=""will clear the wrapper that is associated with the entire shortcode.It will output what you need without needing to add all the HTML and shortcodes – the one new shortcode will output what you were adding with:
<a href="[amazon-element asin='B000I2PONS' fields='url_clean']"> <button>[amazon-element asin='B000I2PONS' fields='price_clean']</button> </a>.
Let me know if you have any issues.
Warm regards,
DonThank you SO much! This works great. 🙂
Not a problem!
- Add this filter/function to your theme’s
The topic ‘Display an Amazon Element without the CSS wrapper?’ is closed to new replies.