The feats Racial Heritage (Human) and Gluttonous Gobbler are the path of least resistance for a typical Pathfinder character. For the typical D&D 3.5e campaign, were this player to want desperately his PC to have the special ability swallow whole at the earliest opportunity, he would try to convince the DM to include in the campaign the Pathfinder feats Racial Heritage (Human) and Gluttonous Gobbler. If the DM were unmoved, then he'd just play a druid.
While the question already briefly addresses some of these options, they're are some that are nonetheless worth examining in greater detail.
While the 2nd-level Sor/Wiz spell alter self [trans] (PH 197) largely prohibits the subject from gaining the assumed form's extraordinary special attacks, the 4th-level Sor/Wiz spell polymorph [trans] (PH 263) et al. do not, making access to an effect like the spell polymorph by far the easiest way to acquire the extraordinary ability swallow whole.
The most convenient way of acquiring such an effect is likely the phylactery of change (Arms and Equipment Guide 135) (11,200 gp; 0 lbs.) that grants the wearer 1/day the ability to use an effect like the spell polymorph as a level 7 caster except with an unlimited duration. Likely unbalanced in contemporary play, the phylactery predates the 3.5 revision therefore is subject to "minor adjustments" by the DM (Dungeon Master's Guide 4). Compare the phylactery with, for example, the skin of proteus (Expanded Psionics Handbook 176) (84,000 gp; 2 lbs.) that grants the wearer at will the ability to use an effect like the psionic power metamorphosis (which likewise can grant the ability swallow whole) as a level 7 manifester.
The remorhaz (Monster Manual 214-15) is a Huge magical beast with 7 Hit Dice, a +11 natural armor bonus, and a burrow speed in addition to the special attacks improved grab and swallow whole, making it a decent form for the aspiring swallower save for the creature's lack of additional attacks, nonhumanoid shape, and inability speak.
As the druid supernatural ability wild shape (PH 36) is based on the supernatural ability alternate form (Monster Manual 305), it grants the creature the assumed form's extraordinary special attacks, including the extraordinary ability swallow whole). Nondruidic wild shape alternatives are provided in answers to this question.
Inconveniently, so far as I'm aware, there is no creature of precisely 5 Hit Dice that's Medium or Small, possesses the animal type, and possesses the ability swallow whole. However, to start off, there is the 2-HD Medium giant toad (Oriental Adventures 195-6) and the 4-HD Medium dire toad (Monster Manual II 42, 46). (Oddly, the 3-HD Medium giant frog (Return to the Temple of Elemental Evil 158) is a magical beast.)
Elegant yet highly controversial is, as a level 10 or higher rogue, taking with the class feature special ability—instead of, for example, the special ability improved evasion—the simply-named special ability feat to gain the monstrous feat Gape of the Serpent (Serpent Kingdoms 663), bypassing its prerequisites.
The special ability feat says, in its entirety, "A rogue may gain a bonus feat in place of a special ability" (PH 51), and the vast majority read the special ability feat as the creature still needing to meet the feat's prerequisites. However, a much smaller minority point to the omission of any mention of prerequisites and to the Monster Manual on Feats (7) as proof that the creature need not meet the picked bonus feat's prerequisites (cf. the fighter's class feature bonus feats ("A fighter must still meet all prerequisites for a bonus feat" (PH 38)), the monk's class feature bonus feat ("A monk need not have any of the prerequisites normally required for these feats…" (PH 41)). Most DMs, I assume, are in the majority.
This author is not taking sides on this issue, but, instead, merely presenting the concept that there's a possibility that the DM may rule that the rogue special ability feat doesn't require the creature to meet the picked feat's prerequisites. Flame wars over this issue have plagued the game since its publication. This author suggests approaching the DM with this possibility cautiously, perhaps after the DM's had a few drinks. Further, this player recommends not abusing it if it is allowed. If the DM says Sure, go ahead and take any ol' feat with the feat special ability, the player should strongly consider picking a dumb but fun and difficult-to-acquire feat like Gape of the Serpent (or, for example, the feat Baleful Moan (Libris Mortis 24-5) or Touch of Hate (Player's Guide to Faerûn 177)) rather than, for example, a potential or actual gamebreaker like Epic Spellcasting (EL 55) (for a rogue 10/sha'ir 1 (Dragon Magazine Compendium, Volume 1 51-7), obviously); Mark of Avernus (Fiendish Codex II 84); Metamorphic Transfer (XPH 48); or Perfect Multiweapon Fighting (EL 64).
(For comparison, the equivalent Pathfinder version of D&D 3.5e rogue special ability feat is the rogue advanced talent feat that eliminates ambiguity by instead saying, "A rogue may gain any feat that she qualifies for….")
The challenging prerequisites for the monstrous feat Snatch and Swallow (Draconomicon 73-4) make it among the least likely ways to get the special ability swallow whole: the general feat Snatch (Monster Manual 304), Improved Snatch (Dr 71), Constitution 19 or higher, the type dragon, and the size category Huge. While it's an inelegant way to acquire the feat, the feat can be acquired with minimum shenanigans. That does not mean that the DM will appove every step!! Everything book-legal isn't also table-right.
For example, a human Clr1 that possesses the template half-minotaur (Dragon #313 94-5) so that she retains her humanoid type but has the size category Large and that's been affected by the 1st-level Sor/Wiz spell enlarge person [trans] (PH 226-7) followed by the 5th-level Sor/Wiz spell permanency [univ] (PH 259-60) (costing at least 2,960 gp) so her size category is Huge and that possesses Constitution 19 or higher (hence at least Con 13 before modifications) and the feat Skill Focus (Diplomacy) (PH 100) and that takes the domain Hunger (Spell Compendium 275) so that she gets a bite attack finally meets the prerequisites for (and can use!) the feats Snatch and Improved Snatch. Then it's a matter advancing a level while the subject of the 2nd-level Sor-only spell essence of the dragon [trans] (Races of the Dragon 112-13) so her type is dragon and taking as that level, for example, the first level of marshal (Miniatures Handbook 11-13) because "[i]f [she] already
has the feat [Skill Focus (Diplomacy)], [s]he can choose a different" feat and taking the elusive feat Snatch and Swallow.
All told, with an exceptionally ridiculous character background and 260 gp of debt, a buck naked just-entering-play half-minotaur human cleric 1/marshal 1 (ECL 3) that takes 1 flaw could have the feat Snatch and Swallow. However, to actually use the feat would require first drinking a potion of essence of the dragon (2nd-level spell at caster level 4) (400 gp; 0.1 lbs.) or another method of regaining the type dragon like, for instance, employing a similar wand (again, 2nd-level spell at caster level 4) (120 gp/charge) somehow (for example, the granted power of the domain Magic (PH 188) is of no help with such a wand) or mucking about with the feat Momentary Alteration (Unearthed Arcana 94) as described in this answer.
The 8th-level Gluttony and Hunger domains spell bite of the king [necro] (Spell Compendium 28) does, indeed, "send a creature to a pocket 'stomach' dimension with a successful melee touch attack" if the creature fails its Fortitude saving throw, but when it "successfully exits [it] appears to cut its way free from thin air, appearing in a space adjacent to" the caster, so it's only sort of like the ability swallow whole.
The even more spectacular alternative is the 8th-level Sor/Wiz spell swallow [conj] (Dragon #323 66) that has "a horrific visual effect as [the caster's] mouth distends, swallowing the target and banishing it to a… chamber with constricting, pulpy walls." While similar to (and likely intended to be replaced by) the spell bite of the king, the spell has no saving throw and a target that frees itself from the chamber reappears, instead, where the swallow spell was cast.
The witch archetype gingerbread witch—I swear I am not making this up—in addition to being able to conjure candy, smell children, and heal its familiar by baking it, gains at level 12 the extraordinary ability gruesome gobbler, which gives the witch
a bite attack that deals 1d6 points of damage for a Medium witch. As a full-round action, [the gingerbread witch] can make a single bite attack that deals double base damage (2d6 for a Medium witch) and functions as if she had the grab and swallow whole special attacks, allowing her to grab and swallow a creature of her size or smaller.
The special ability is complicated—it's over 250 words!—, but it does what's required with the minimum of shenanigans. That the archetype is icky is probably beside the point: is there a pleasant way to swallow whole?
The ogre as a race has a Race Point (RP) value of 23, within spitting distance of the aasimar (15 RP), android (16 RP), fetchling (17 RP), wyrwood (20 RP), and wyvaran (17 RP), so a generous GM may allow into a group of PCs that've already picked such powerful races a creature slightly more powerful like this one. While the feat's prerequisites are steep—typically Improved Unarmed Strike and Improved Grapple (hence also Dex 13) in addition to being a Large ogre—, the feat Gluttonous Gobbler has the following benefit:
If you start your turn grappling another creature at least two size categories smaller than you, you can put the grappled creature in your mouth as a move action and attempt another grapple combat maneuver check (as though attempting to pin the opponent). If you succeed, you swallow the opponent as if you had the swallow whole special ability.
It's apparent, however, that the feat wasn't fully playtested: The extraordinary ability swallow whole says, "The amount and type of damage [dealt to a swallowed foe] varies and is given in the creature’s statistics," yet that information's absent. The GM must make some decisions even though the feat technically exists.
Also see the feat Racial Heritage (Human)—ogre is an option as Pathfinder giants are a subtype of humanoid—, allowing a very complicated human to pick up eventually the feat Gluttonous Gobbler. Also see the third-party race half-ogre, who (like the aforementioned complicated human) needs a permanent enlarge person before he can take the feat Gluttonous Gobbler.
Best Answer
Base classes are base classes because they are assumed to be things that just about anyone can do, join, or become. That is why you are able to freely choose among them when selecting your next level.
Prestige classes are special classes that are not simply assumed to be things that just about anyone can do at the drop of a hat—they require special preparation and training that goes beyond just the one level-up. That is why they have prerequisites.
Templates aren’t classes at all; they aren’t assumed to be something anyone can just do. Instead, they are more like things that happen to people. Templates are the result of curses, magical transformations, great blessings, or whatever—when they aren’t just hereditary.
So gaining a template doesn’t generally happen when you level up—and they certainly aren’t something you can choose to have happen when you level up just because those are the benefits you’d like best from your level. Rather, they happen when they get applied—by curse, or disease, or ritual, or divine intervention, or whatever. (When they get applied, they basically count as if you were already higher level, which delays your next level-up.) Sometimes those are things you can control—the lich template is a prime example—or can attempt to have happen on purpose—think purposefully getting bit by a vampire or werewolf. But other times they are completely outside your control.
In all cases, if you are interested in gaining a template, you should speak with the GM about it. The appropriate thing for a GM to do is evaluate the template, decide if they want to allow it on a PC—some of them are bad ideas for PCs—and then work with the player to allow the situation necessary to apply the template to occur in the story. Sometimes that’s easy, other times it’s hard, and of course some times there just isn’t really a good way to work it in even if the template itself would be OK. But a GM should try, if at all possible (and, again, they deem the template itself acceptable), because it’s a great plot hook and offers fantastic opportunity for character development, plus it makes the player happy.
I have also known GMs to grant, as part of the story, the option of “leveling” into a template. In effect, something in the story has changed the character—or revealed something about the character—and they now have latent abilities they could tap into. It doesn’t happen automatically (and the player could choose not to, if there are other things they’d prefer to level into), but it’s a good way to handle things.
But as a word of caution, templates tend to be very problematic because they make you “count as” a higher level without actually being a higher level. You usually get some potent abilities for it, but you also tend to miss out on some important things a level would have otherwise gotten—hp, saving throw bonuses, skill ranks, feats, and so on are all delayed by the template. That can be very severe, and personally I tend to try to avoid them altogether as a result, both as GM and player. When a player comes to me looking to use a template, I usually try to either revise it to make it “+0,” that is, benefits and drawbacks in equal measure (and both kind of on the small side), or else turn it into a proper “level” to take, complete with hd, base saving throws, skill points, and so on (this works well with the “level into” concept above).