The aim of this study was to determine the most appropriate treatment for the duration of ultrasonic pretreatment at two different temperatures in the process of anaerobic digestion (AD) of ruminal contents in the slaughterhouse. The experiments were performed at the Golshan industrial slaughterhouse in Lorestan province. In this study, after homogenizing the rumen contents of different animals, the effect of ultrasonic pretreatment time at three different intervals of 10, 20, and 30 min at two different temperatures of 30 °C and 40 °C was investigated to determine the effect of variables related to the trend of changes in methane, total biogas, and daily biogas production. The Taguchi L18 method was used to investigate the process conditions and achieve optimal production conditions for biogas methane. The results showed that with an increase in pretreatment time up to 30 min and the temperature up to 40 °C, the production of biogas and methane also increased. The highest amount of methane, total biogas, and daily biogas produced was related to the use of ultrasonic pretreatment for 30 min at 40 °C with 50.66 % methane, total biogas production of 332.66 mL/gVS, and the best performance compared to other treatments in the shortest possible time. Therefore, the use of ultrasonic pretreatment over longer periods and at higher temperatures improves the AD process and produces more total methane and biogas. Finally, this research presented equations for the production of biogas and methane at a time of 10–30 min and a temperature of 30–40 °C, which showed high accuracy.