No, this is not true in general, even for connected Lie groups.
The special linear group $\operatorname{SL}_4$ in dimension 4 over a ring of characteristic not 2 (e.g. $\mathbb{R}$, resulting in a connected Lie group) is not a direct product of $Z(G)$ and $G/Z(G)$. This is because $-I$ is a commutator and in the center, but in $A \times B$ with $A$ abelian, the commutator subgroup is $1 \times [B,B]$, so that $[G,G] \cap Z(G) = 1$ in any such group with $A=Z(G)$. Explicitly, $$\tiny
\left(\begin{array}{rrrr}
-1& 0& 0& 0 \\
0& 1& 0& 0 \\
0& 0&-1& 0 \\
0& 0& 0& 1 \\
\end{array}\right)^{-1} \cdot
\left(\begin{array}{rrrr}%
0&1&0&0\\%
1&0&0&0\\%
0&0&0&1\\%
0&0&1&0\\%
\end{array}\right)^{-1} \cdot
\left(\begin{array}{rrrr}
-1& 0& 0& 0 \\
0& 1& 0& 0 \\
0& 0&-1& 0 \\
0& 0& 0& 1 \\
\end{array}\right) \cdot
\left(\begin{array}{rrrr}%
0&1&0&0\\%
1&0&0&0\\%
0&0&0&1\\%
0&0&1&0\\%
\end{array}\right) =
\left(\begin{array}{rrrr}%
-1&0&0&0\\%
0&-1&0&0\\%
0&0&-1&0\\%
0&0&0&-1\\%
\end{array}\right)%
$$
In fact, we can give a fairly tautological classification of the groups $G$ with $G \cong Z(G) \rtimes G/Z(G)$. Since $Z(G)$ is central, the semi-direct product is actually direct, $G \cong Z(G) \times G/Z(G)$, but the center of $A \times B$ is $Z(A) \times Z(B)$, so we must have $Z(G/Z(G)) = 1$. Hence $G$ is of the form $A \times B$ where $A$ is abelian and $B$ is centerless. Conversely, if $G$ if of the form $A \times B$ where $A$ is abelian and $B$ is centerless, then $Z(G) = A \times 1 \cong A$ and $G/Z(G) \cong B$, as required.
Proposition: $G \cong Z(G) \times G/Z(G)$ iff $G \cong A \times B$ where $A$ is abelian and $B$ is centerless.