Home Forums Pro Themes Photomania Pro Request to amend the code to work on my site

Tagged: 

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #138726
    stiver1
    Participant

    Hi
    Brother, I installed a code
    I am facing a problem

    He’s doing well here
    But the problem is when I put a picture of the article uploaded
    And everything is fine

    And when I click to add it it does not appear
    the problem

    The 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;
    
    }
    #138949
    wensolutions
    Keymaster

    Hello,

    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.

    #138950
    stiver1
    Participant
    #139054
    wensolutions
    Keymaster

    Hello,

    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.

    #139070
    stiver1
    Participant

    I want to schema for images

    itemprop = “image” itemscope itemtype = “https://schema.org/ ImageObject”

    #139264
    wensolutions
    Keymaster

    Hello,

    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.

    #139269
    stiver1
    Participant
    #139289
    wensolutions
    Keymaster

    Hello,

    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.

    #139304
    stiver1
    Participant

    I put the code down

    but

    The image does not appear after I uploaded it

    https://i.top4top.io/p_1789qmuxz1.png

    https://a.top4top.io/p_17894lvpf1.png

    #139379
    wensolutions
    Keymaster

    Hello,

    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.

    #139462
    stiver1
    Participant

    Is there anything new about the code?

    #139515
    wensolutions
    Keymaster

    Hello,

    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.

    #140341
    stiver1
    Participant

    Hello

    Unfortunately, I did not find help on any site
    Help me

    thank you

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.