This question was prompted by this study by Mohsen Javdani and Ha-Joon Chang, which tries to show two things: mainstream economists are biased against heterodox economists, and also tend to favour statements by those close to their own political viewpoint, particularly on the right. I don’t want to talk here about the first bias, or about the merits or otherwise of this particular study. Instead I will take it as given that ideological bias exists within mainstream academic economists (and hereafter when I just say ‘academic economics’ I’m only talking about the mainstream), as it does with many social sciences. I take this as given simply because of my own experience as an economist.
I also, from my own experience, want to suggest that in their formal discourse (seminars, refereeing etc) academic economists normally pretend that this ideological bias does not exist. I cannot recall anyone in any seminar saying something like ‘you only assume that because of your ideology/politics’. This has one huge advantage. It means that academic analysis is judged (on the surface at least) on its merits, and not on the basis of the ideology of those involved.
The danger of doing the opposite should be obvious. Your view on the theoretical and empirical validity of an academic paper or study may become dependent on the ideology or politics of the author or the political implications of the results rather than its scientific merits. Having said that, there are many people who argue that economics is just a form of politics and economists should stop pretending otherwise. I disagree. Economics can only be called a science because it embraces the scientific method. The moment evidence is routinely ignored by academics because it does not help some political project economics stops being the science it undoubtedly is.
Take, for example, the idea - almost an article of faith in the Republican party - that we are on the part of the Laffer curve where tax cuts raise revenue. The overwhelming majority, perhaps all, of academic economic studies find this to be false. If economics was merely politics in disguise, this would not be the case. This is also what distinguishes academic economics and some of the economics undertaken by certain think tanks, where results always seem to match the political or ideological orientation of the think tank.
There is a danger, however, in pretense going too far. This can be particularly true in subjects where empirical criticism of assumptions or parameterisation is weak. I think this was the basis of Paul Romer’s criticism of growth theory and microfoundations macro for what he calls mathiness, and by Paul Pfleiderer for what he calls ‘chameleon models’ in finance and economics. If authors choose assumptions simply to derive a particular politically convenient result, or stick to simplifications simply because it produces results that conform to some ideological viewpoint, it seems absurd to ignore this.
Romer’s discussion suggests that it is at least possible for ideological bias to send a branch of economics off in the wrong direction for some time. I would argue, for example, that Real Business Cycle theory in business cycle macro, which was briefly dominant around 40 years ago, was in part influenced by a desire among those who championed it to look for models where policy had little role. In addition, it showed up economists tendency to ignore other social sciences, or even common sense, at its worse.  It didn’t last because explaining cycles is so much easier when you assume sticky prices, as most macroeconomists now do, but it may be possible that other aspects of mainstream economics may be ideologically driven and persist for a much longer time (Pareto optimality?), and mainstream economists should always be aware of that possibility. One of my first posts was about the influence of ideology on the reaction of some economists to Keynesian fiscal stimulus.
The basic problem arises in part because empirical results are never clear cut and conclusive. For example the debate about whether increases in the minimum wage reduce employment continues, despite plenty of empirical work that suggests it does not, because there is some evidence that points the other way. This opens the way for ideology to have an influence. But the political implications of academic economics will always mean that ideology plays a role, whatever the evidence. Even when evidence is clear, as it is for the continuing importance of gravity (how close two countries are to each other) for trade for example, it is possible for an academic economist to claim gravity no longer matters and gain a huge amount of publicity for their work that assumes this. This is an implication of academic freedom, although in the case of economics, I still think there is a role for an organisation like (in the UK) the Royal Economic Society to point out what the academic consensus is.
Does this mean economics is not a true science? No, because ideological influence does not trump data when the data is very clear, as in the case of the Laffer curve or gravity equations, although ideology and academic freedom may allow the occasional maverick to go against the consensus. That in turn means that it is important for any user of economics to be aware of possible ideological bias, and always establish what the consensus is, if it exists, on an issue. Could ideology influence the direction particular areas of economics take for some time? The evidence cited above suggests yes. So while I have no quarrel with the pretense that ideology is absent from academic economics in formal discourse, academics should always be aware of its existence. In this respect, some of the points that the authors of this study mention in the discussion section of their paper are relevant.
 This reflected the introduction of a microfoundations methodology which soon began to dominate the discipline, and which I have talked about elsewhere (e.g. here and here).