Site logo

[Resolved] Rank Math not seeing container background Images and Alt Titles

Home Forums Support [Resolved] Rank Math not seeing container background Images and Alt Titles

Home Forums Support Rank Math not seeing container background Images and Alt Titles

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #2468914
    troyw

    Hey team,
    I can see I am very much not alone with this issue, but out of the many posts about this topic, I am yet to find one with a clear solution. The problem is not just with GP, it is pretty much all themes and builders.

    Rank Math cannot locate images used as a container background. It simply does not see them at all.
    I contacted Rank Math and they sent me a link I had already looked at https://rankmath.com/kb/content-analysis-api/
    This help page isn’t all that helpful, but they do provide a link to an example bit of PHP.

    /**
     * External Dependencies
     */
    import jQuery from 'jquery'
    import { debounce } from 'lodash'
    
    /**
     * RankMath custom fields integration class
     */
    class RankMathCustomFields {
    	/**
    	 * Class constructor
    	 */
    	constructor() {
    		this.init()
    		this.hooks()
    		this.events()
    	}
    
    	/**
    	 * Init the custom fields
    	 */
    	init() {
    		this.fields = this.getFields()
    		this.getContent = this.getContent.bind( this )
    	}
    
    	/**
    	 * Hook into Rank Math App eco-system
    	 */
    	hooks() {
    		wp.hooks.addFilter( 'rank_math_content', 'rank-math', this.getContent, 11 )
    	}
    
    	/**
    	 * Capture events from custom fields to refresh Rank Math analysis
    	 */
    	events() {
    		jQuery( this.fields ).each( function( key, value ) {
    			jQuery( value ).on(
    				'keyup change',
    				debounce( function() {
    					rankMathEditor.refresh( 'content' )
    				}, 500 )
    			)
    		} )
    	}
    
    	/**
    	 * Get custom fields ids.
    	 *
    	 * @return {Array} Array of fields.
    	 */
    	getFields() {
    		const fields = []
    		jQuery( '#the-list > tr:visible' ).each( function( s, e ) {
    			const key = jQuery( '#' + e.id + '-key' ).val()
    			if ( -1 !== jQuery.inArray( key, rankMath.analyzeFields ) ) {
    				fields.push( '#' + e.id + '-value' )
    			}
    		} )
    
    		return fields
    	}
    
    	/**
    	 * Gather custom fields data for analysis
    	 *
    	 * @param {string} content Content to replce fields in.
    	 *
    	 * @return {string} Replaced content.
    	 */
    	getContent = function( content ) {
    		jQuery( this.fields ).each( function( key, value ) {
    			content += jQuery( value ).val()
    		} )
    
    		return content
    	}
    }
    
    jQuery( function() {
    	setTimeout( function() {
    		new RankMathCustomFields()
    	}, 500 )
    } )

    Again, this is about as much use as an ash-tray on a motorbike and doesn’t help understand what needs to be edited in order to get Rank Math to see the Blocks.

    From what I have read, the standard response from Rank Math on this topic is the same for pretty much all themes and site-builders. “Content Analysis API – Integrate Your Theme or Plugin with Rank Math SEO”

    Are you able to assist me in deciphering their vague clues to make Rank Math work with Generatepress Background Images.
    Many thanks

    #2468931
    troyw

    Additionally, I added this to the functions.php and it still does not work.

    add_filter( ‘rank_math/schema/nested_blocks’, function( $nested ) {
    $nested[] = ‘generateblocks/container’;
    $nested[] = ‘generateblocks/grid’;
    return $nested;
    });
    #2469189
    David
    Staff
    Customer Support

    Hi there,

    background images are displayed using CSS.
    They themselves are not written in HTML like an <img> and therefore there is no ALT tags or other attributes.

    if the image is important content and you need it to be seen and ALT tags / other attributes to be readable then you would need to use an image block instead of a background image.

    #2469911
    troyw

    Hey team,

    Thanks for getting back to me with this David. The problem I have with using images, is that they do not seem to play nice in the content blocks. For example, on the Home page you will see that I have removed the background image and put an image block in the container instead. The main issue is that no matter what I do, the image won’t fit neatly into the box. I have played with the Image dimensions in the image block, but no matter what I do, it is not high enough. Additionally, the image sits over the top left curved border. The background images just seem to work so much better.
    How can I get the Images to act like the background images?

    Thanks

    #2469932
    troyw

    I seem to have resolved this now by using the other Image Block available and adding in all the Image Corners top match the container corners. A bit long winded, but it works I think.

    Cheers

    #2470201
    David
    Staff
    Customer Support

    Glad to hear you found a solution.

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