0

I want to get sidebar & footer including html of current post.

Then I want to check a "string" inside sidebar & footer. If "string" exits, I want to enqueue a custom script.

If anyone knows a function to do so, please help me. thanks

Note: following functions get just content section of a post. So please suggest a function which gets full html including head, body, sidebar, footer.

the_content();

get_the_content();

$post = get_post();
$post->post_content

One thing I know, I have to use stripos() to check "string".

  • What string are you looking for? There may be a better way to solve this problem using a hook or filter. Depends on what you are trying to accomplish – czerspalace Dec 20 '18 at 21:57
  • How is that comment being added to the head? – czerspalace Dec 20 '18 at 22:06
  • Then it would be on every post, so why do you need to check for it? – Jacob Peattie Dec 21 '18 at 0:03
  • 1
    @samar it looks like you had a problem, and you devised a solution involving a html comment, but you don't know how to implement it. Why did you ask about the solution instead of the original problem? E.g. if you're trying to enqueue a script but only if a widget appears, or a shortcode, why not ask about that instead? Context is super important! In order to do what you want, you're going to need to use output buffers, and that brings with it some significant performance problems, so much so that condiitonally loading the script would be faster, but there's other solutions that are better – Tom J Nowell Dec 21 '18 at 1:03
  • 1
    Also, if you generate the entire HTML, then you have a catch 22 because you need to enqueue your scripts before the header, but once you've gotten the entire page to check the result, that's already happened, and it's too late – Tom J Nowell Dec 21 '18 at 1:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.