Home › Forums › Pro Themes › Photomania Pro › Request to amend the code to work on my site
Tagged: code
- This topic has 11 replies, 2 voices, and was last updated 2 years, 10 months ago by
stiver1.
-
AuthorPosts
-
November 18, 2020 at 4:09 am #138726
stiver1
ParticipantHi
Brother, I installed a code
I am facing a problemHe’s doing well here
But the problem is when I put a picture of the article uploaded
And everything is fineAnd when I click to add it it does not appear
the problemThe image is flying well
But it does not appear when I click on add a featured image
There is something in the code that prevents this
add_filter ( 'wp_get_attachment_image_attributes', 'wp_image_attributes', 10, 3); function wp_image_attributes( $attr, $attachment, $size ) { echo '<span itemprop="image" itemscope itemtype="https://schema.org/ImageObject">'; $kora_image = wp_get_attachment_image_src( get_post_thumbnail_id(),$attr, $attachment_id, $size, 'kora-featured-image' ); echo '<meta itemprop="url" content="' . esc_url( $kora_image[0] ) . '">'; echo '<meta itemprop="width" content="' . esc_attr( $kora_image[1] ) . '">'; echo '<meta itemprop="height" content="' . esc_attr( $kora_image[2] ) . '">'; $attr['itemprop'] = 'image'; return $attr; }
November 19, 2020 at 5:40 am #138949wensolutions
KeymasterHello,
Regarding your query, once please provide us with some details, what is your exact query/issue and from where you found the above code please let us know.
This will help us inspect in detail about the error.
Regards.
November 19, 2020 at 6:08 am #138950stiver1
ParticipantNovember 20, 2020 at 6:08 am #139054wensolutions
KeymasterHello,
Regarding your query, the link you have provided has code which is wrong so which is why the code is not working as per your requirement.
Further, please let us know what exactly do you want to have in the image area. So, explain your query in detail so that we can be more clear and help you precisely. Also, please provide us with proper screenshots highlighting the sections.
Hoping for your kind co-operation.
Regards.
November 20, 2020 at 7:19 am #139070stiver1
ParticipantI want to schema for images
itemprop = “image” itemscope itemtype = “https://schema.org/ ImageObject”
November 24, 2020 at 1:25 am #139264wensolutions
KeymasterHello,
Regarding your query, we have modified and optimized your earlier provided code to make it compatible for schema and SEO purpose. This below code will only add schema properties to those image tags which are generated using “the_post_thumbnail();” function. You need to paste this code snippet in your child themes’ functions.php file or in your custom plugin, please never put code snippets in main theme files directly as that can remove all the changes during theme update. Also you should not make any modification directly in your parent theme as all of the customizations will be lost upon update to the latest version of the plugin.
So please go through the child theme for the changes. Below link helps you to create child theme.
https://wptravel.io/how-to-create-a-child-theme/
/** * Adds schema information to WordPress generated image tag. */ function stiver1_wp_image_schema_attributes( $attr, $attachment, $size ) { $attachment_id = isset( $attachment->ID ) ? $attachment->ID : 0; if ( ! $attachment_id ) { return $attr; } $kora_image = wp_get_attachment_image_src( $attachment_id, $size ); echo '<span itemprop="image" itemscope itemtype="https://schema.org/ImageObject">'; echo '<meta itemprop="url" content="' . esc_url( $kora_image[0] ) . '">'; echo '<meta itemprop="width" content="' . esc_attr( $kora_image[1] ) . '">'; echo '<meta itemprop="height" content="' . esc_attr( $kora_image[2] ) . '">'; echo '</span>'; $attr['itemprop'] = 'image'; return $attr; } add_filter( 'wp_get_attachment_image_attributes', 'stiver1_wp_image_schema_attributes', 10, 3 );
Hope this helps.
Please get back to us if the above code snippet didn’t work for you.
Regards.
November 24, 2020 at 2:43 am #139269stiver1
ParticipantHi
I added the code, but the image does not appear in the article
https://k.top4top.io/p_1789l666i1.png
November 24, 2020 at 6:43 am #139289wensolutions
KeymasterHello,
Once please replace below given Code with previous to fix the issue you have mentioned.
/** * Adds schema information to WordPress generated image tag. */ function stiver1_wp_image_schema_attributes( $attr, $attachment, $size ) { $is_edit = isset( $_GET['context'] ) ? 'edit' === $_GET['context'] : ''; if ( $is_edit ) { return $attr; } $attachment_id = isset( $attachment->ID ) ? $attachment->ID : 0; if ( ! $attachment_id ) { return $attr; } $kora_image = wp_get_attachment_image_src( $attachment_id, $size ); echo '<span itemprop="image" itemscope itemtype="https://schema.org/ImageObject">'; echo '<meta itemprop="url" content="' . esc_url( $kora_image[0] ) . '">'; echo '<meta itemprop="width" content="' . esc_attr( $kora_image[1] ) . '">'; echo '<meta itemprop="height" content="' . esc_attr( $kora_image[2] ) . '">'; echo '</span>'; $attr['itemprop'] = 'image'; return $attr; } add_filter( 'wp_get_attachment_image_attributes', 'stiver1_wp_image_schema_attributes', 10, 3 );
Hope this helps.
Please get back to us if the above code snippet didn’t work for you.
Regards.
November 25, 2020 at 2:04 am #139304stiver1
ParticipantI put the code down
but
The image does not appear after I uploaded it
November 25, 2020 at 7:13 am #139379wensolutions
KeymasterHello,
Regarding your query, actually we tried to improvise the code you have provided. Further, you can consider hiring a freelancer.
Actually the code you wanted is not from our theme and has arrived from the third party plugins.
Regards.
November 26, 2020 at 7:32 am #139462stiver1
ParticipantIs there anything new about the code?
November 26, 2020 at 11:17 pm #139515wensolutions
KeymasterHello,
Actually, as we tried to fix the code which is not working after changes too and this is beyond the support we provide for our free theme user.
Further, image is appearing fine with the only free version of the theme too so while using external code and third party plugins might bring plugin conflict and some functionality issues. Hence, we suggest our user to use recommended plugins and the plugins that are compatible to the theme.
Hoping for your kind co-operation.
Regards.
December 10, 2020 at 5:08 am #140341stiver1
ParticipantHello
Unfortunately, I did not find help on any site
Help methank you
-
AuthorPosts
- You must be logged in to reply to this topic.