The Wiener index of a connected graph G is W ( G ) = ∑ { u , v } ⊆ V ( G ) d G ( u , v ) . In this paper, we obtain the Wiener index of H-generalized join of graphs G 1 , G 2 , … , G k . As a consequence, we obtain some earlier known results in [Alaeiyan et al. in Aust. J. Basic Appl. Sci. (2011) 5(12): 145–152; Yeh et al. in Discrete Math. (1994) 135: 359–365] and we also obtain the Wiener index of the generalized corona product of graphs. We further show that the ideal-based zero-divisor graph Γ I ( R ) is a H-generalized join of complete graphs and totally disconnected graphs. As a result, we find the Wiener index of the ideal-based zero-divisor graph Γ I ( R ) and we deduce some of the main results in [Selvakumar et al. in Discrete Appl. Math. (2022) 311: 72–84]. Moreover, we show that W ( Γ I ( Z n ) ) is a quadratic polynomial in n, where Z n is the ring of integers modulo n and we calculate the exact value of the Wiener index of Γ Nil ( R ) ( R ) , where Nil(R) is nilradical of R. Furthermore, we give a Python program for computing the Wiener index of Γ I ( Z n ) if I is an ideal of Z n generated by pr , where pr is a proper divisor of n, p is a prime number and r is a positive integer with r ≥ 2 .