Context. In the standard scenario of planet formation, terrestrial planets and the cores of the giant planets are formed by accretion of planetesimals. As planetary embryos grow, the planetesimal velocity dispersion increases because of gravitational excitations produced by embryos. The increasing relative velocities of the planetesimal cause them to fragment through mutual collisions. Aims. We study the role of planetesimal fragmentation on giant planet formation. We analyze how planetesimal fragmentation modifies the growth of giant planet cores for a wide range of planetesimal sizes and disk masses. Methods. We incorporated a model of planetesimal fragmentation into our model of in situ giant planet formation. We calculated the evolution of the solid surface density (planetesimals plus fragments) taking into account the accretion by the planet, migration, and fragmentation. Results. Incorporating planetesimal fragmentation significantly modifies the process of planetary formation. If most of the mass loss in planetesimal collisions is distributed in the smaller fragments, planetesimal fragmentation inhibits the growth of the embryo for initial planetesimals of radii smaller than 10 km. Only for initial planetesimals with a radius of 100 km, and disks larger than 0.06 M ⊙ , embryos achieve masses larger than the mass of Earth. However, even for these large planetesimals and massive disks, planetesimal fragmentation induces the quick formation of massive cores only if most of the mass loss in planetesimal collisions is distributed in the larger fragments. Conclusions. Planetesimal fragmentation seems to play an important role in giant planet formation. The way in which the mass loss in planetesimal collisions is distributed leads to different results, inhibiting or favoring the formation of massive cores.