code: def add_layer_to_canvas(layer, name):
      
      if qgis_version() >= 21800:
          layer.setName(name)
      else:
          layer.setLayerName(name)
  
      QgsProject.instance().addMapLayer(layer, False)
docs: Helper method to add layer to QGIS.
  
      :param layer: The layer.
      :type layer: QgsMapLayer
  
      :param name: Layer name.
      :type name: str