I want to add Scrollspy support to the nav-menu, for that I have to add extra attributes data-spy="scroll" data-target=".navbar" to the body tag.
Can I do that pragmatically without touching theme files?
On
Pretty sure this can't be done without editing the theme files. You could try the jQuery method that tousif has mentioned above but I doubt it will work as it will most likely fire after ScrollSpy has been loaded.
Best way to do this is to edit your 'header.php' file and add the attributes to the <body> tag. You shouldn't edit the theme itself though, use a child theme - https://codex.wordpress.org/Child_Themes
One way would be to:- Edit
header.phpAnd add those attributes to the body.Alternative (without editing theme files) way would be to create a plugin which adds a js that adds those attributes to body. Something like this:-
EDIT After viewing Sevi's answers. The most suitable way is