• Resolved prodefu

    (@prodefu)


    Hi Ryan,

    Thanks for your plugin, keep up the good work of updating it regularly!

    I do miss one thing though in your instructions: how I can call the unique header field in a template.

    I do have a website that has a header section and this uses the featured image of a post as header image:

    <?php if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
    	echo 'style="background-image: url(\'';
    	the_post_thumbnail_url('post-background'); 
    	echo '\'); background-repeat: no-repeat; background-position: center center; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover;"';
    }
    ?>

    But for one post type the features image is square and not suitable as header image. That’s why I want to add some code to the header, to check first if a custom header has been set.

    I would like to use it something like this (don’t mind the ‘syntax’, I just describe the ‘if-then-else’ statements):

    “if ‘page template = X’ ->
    if isset(custom header) { return custom header image }
    else ‘return default header image’ // (either enter url here manually or set default header image somewhere else for all posts, if possible)
    else ‘do default code like shown above'”.

    So compared to my current code I’m looking for the ‘has_post_thumbnail()’ equivalent (to check if custom header is set) and the ‘the_post_thumbnail_url(‘post-background’)’ equivalent for your plugin. Could you add some code snippets for this to the description, like WP User Avatar did (scroll down to the ‘advanced settings’ in the descritpion)? Would appreciate it very much!

    • This topic was modified 6 years, 11 months ago by prodefu.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Ryan Hellyer

    (@ryanhellyer)

    Since it’s just modifying the header image, you can call it in your template just as you would a regular header image (since that’s what it is). I don’t include instructions for that, since it’s a WordPress core thing, not something implemented by the plugin itself.

    The other parts of your question are relating to post thumbnails, which are something different and not directly related to header images.

    Thread Starter prodefu

    (@prodefu)

    Hi Ryan,

    Thanks for your replay, but this is not the answer I expected – it feels a bit blunt, to be honest. But maybe I was not clear enough in my original post about what I’m actually asking.

    Basically I’m trying to use your plugin with a custom header template part; I think many more users like me would want to know how to do this.

    If I encounter a problem in WordPress, I alwasy try to think of a solution that would benefit not only me, but all users with the same problem. So I think it would improve your plugin if you could implement a shortcode to load the set custom header image at any place, thus also in a custom header template part.

    The theme of my website is using it’s own header template part, so by default it does not work with your plugin. But by default the posts and pages did not show any header background image, until I modified the header template part to load the featured image as background. So it should be not too difficult to extend this with some code from your plugin for the custom header image as well.

    I know that the featured image URL is loaded by ‘the_post_thumbnail_url(‘post-background’)’ in the code of the header template part. I’m now just looking for a simple code snippet to replace this with the URL of the set custom header image and to include a check if a custom header image is set.

    I’ve been looking for this for quite a while now, but just can’t find out yet (still improving/learning my coding skills…). And since you are the author of the plugin, I suppose it’s a piece of cake for you to give me this snippet or at least put me in the right direction. It would save me a lot of time and trouble, would be much appreciated!

    Plugin Author Ryan Hellyer

    (@ryanhellyer)

    The plugin is intended for adding unique headers into the existing WordPress header system, not for implementing the WordPress header system itself. Such a plugin may be useful, but it would be a different plugin with a different purpose.

    Thread Starter prodefu

    (@prodefu)

    Thanks, that’s a clear answer. Just for the record: I don’t want to implement the WordPress header system itself with your plugin, that’s already in place – be it a custom template part of my theme.

    I still think it’s a pity that your plugin only works with the default WP header system, while it should be so easy to extend it with use for a custom header template part. It could make your plugin the all-round custom header solution that can work with every theme that has a header system in place.

    But I respect your choice not to do this, it’s your plugin after all. So in this case I will look for a different plugin.

    Plugin Author Ryan Hellyer

    (@ryanhellyer)

    It does (in theory) work with every theme that uses the WordPress header system. It doesn’t matter if the header is implemented within a template part or not; whether code is loaded via a template part or not should be irrelevant.

    • This reply was modified 6 years, 11 months ago by Ryan Hellyer.
    Thread Starter prodefu

    (@prodefu)

    Well, thanks for your explaining (I learned something from it), but in the end the feeling remains that you do not really want to help me solve this issue. I think you and I think differently about helping someone out. I respect that.

    You can close this topic for now, but just for the record: it’s not (yet) resolved

    Plugin Author Ryan Hellyer

    (@ryanhellyer)

    This is a topic for the Unique Headers plugin. Your question is not about the plugin, it’s a request for assistance with how to use the WordPress header system.

    I am here to help with the plugin. I’m not a help desk for generic WordPress questions ??

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Code to use in template’ is closed to new replies.