i have to get the post content into the tag <head>.
I was trying with this code into the header.php file of my theme:
if(is_single()){
$stringa = the_content();
}
but it doesn’t work.
how can i do?
thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The functions
the_content()andget_the_content()are meant to be used inside the WordPress loop, which means you can’t just use them at will. You’ll need to build a loop inside yourheader.phpfile that queries the WordPress database, fetches some content, and uses it as necessary.Basically, wrap your
the_content()call inside:Then you’ll be able to fetch post content anywhere on the page … however, I don’t quite understand why you’re trying to get the post content inside the
<head>section of the page.<head>is used for style declarations,<script>tags, and meta information about the page … not for actual page content. If you’re trying to get specific information about the current page, I’d recommend using a different function entirely.