• I want to add some Schema.org code to my website, which should go in the HEAD section. However the Schema.org code is different across different posts (and some posts won’t have this particular Schema code at all.) As such I can’t just use WP-INSERT to copy and paste code across all posts and pages.

    What’s the easiest way of adding different code to HEAD section that I can change depending on the post?

    Cheers

Viewing 3 replies - 1 through 3 (of 3 total)
  • Easiest way is to use a plugin that does it already.
    Other way is to write a plugin (can be small) that calls add_action for ‘wp_head’ to output the information.

    Moderator bcworkz

    (@bcworkz)

    Adding to what Joy said, “wp_head” fires outside of the Loop. We can customarily only determine specific post data within the Loop. As it happens, if is_single() returns true, the requested post object seems to be already assigned to global $post. It would be a good idea to verify it’s assigned an object before attempting to use it. If it is not set for some reason, the requested object can be had with get_queried_object(). This function does not necessarily return a post object, so confirm it’s a WP_Post object before trying to use it as such.

    I need this function too. I need to have certain pages noindex and no plugin has been able to do it even though they all say they can.

    I saw an article that in Sept Google is changing what will be acceptable to noindex so I am of the mind that if the plugins do not work now, what will happen when Sept rolls around?

    So I am left with the prospect of individually going in an coding each page myself! But at least then I will know it’s done and won’t suddenly not work because a plugin was doing it the unacceptable way (if I could even get one to work now). Not a happy camper at all!

    BUT cannot find how to access the actual html of a Page. NOT a universal header change! I certainly don’t want to noindex my entire site!

    Is there any hope for me, a non-geek?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘add code to head section at post level’ is closed to new replies.