Suppose we have a symmetric matrix $\mathcal{D} \in \mathbb{R}^{3 \times 3}$, and this matrix is multiplied by a gradient vector $\nabla p \in \mathbb{R}^3$, and finally we calculate the dot product of the result with another vector $S \in \mathbb{R}^3$: $$\bigg ( \mathcal{D} (\nabla p) \bigg ) . S$$
To simplify this, my textbook made the following transformations:
$$ \begin{align} \bigg ( \mathcal{D} (\nabla p) \bigg ) . S &= \color{red}{\bigg ( (\nabla p) \mathcal{D}^\intercal \bigg ) . S} \\ &= \color{blue}{ (\nabla p) . \bigg ( \mathcal{D}^\intercal S \bigg ) } \\ &= (\nabla p) .S^\prime \end{align} $$
I don't understand the steps in red (transposing $\mathcal{D}$ and taking it to the other side of the multiplication, which in this case dimensions of the multiplication don't make sense) and in blue (Is that some property of the dot product to allow such manipulation?).
For the matrix product $\ \mathcal{D}(\nabla p)\ $ to make sense you have to take $\ \nabla p\ $ to be a $\ 3\times1\ $ column vector, and then the result will also be a $\ 3\times1\ $ column vector. If you're taking all your vectors in $\ \mathbb{R}^3\ $ to be $\ 3\times1\ $ column vectors, then the dot product, $\ X\cdot Y\ ,$ of two such is, by definition, \begin{align} \sum_\limits{i=1}^3X_iY_i&=X^\top Y\\ &=Y^\top X \end{align} where $\ X_i,Y_i\ $ are their entries. Applying this to your dot product $\ \big(\mathcal{D}(\nabla p)\big)\cdot S\ ,$ and using the fact that $\ (AB)^\top=B^\top A^\top\ $ for any well-defined matrix product, you get \begin{align} \big(\mathcal{D}(\nabla p)\big)\cdot S&=\big(\mathcal{D}(\nabla p)\big)^\top S\\ &=\left((\nabla p)^\top \mathcal{D}^\top\right)S\\ &=(\nabla p)^\top\big(\mathcal{D}^\top S\big)\\ &\hspace{3em}\text{(from associativity of matrix multiplication)}\\ &=(\nabla p)\cdot\big(\mathcal{D}^\top S\big)\ . \end{align}