We have one custom requirement that when we add an image (suppose a car image) in the homepage, after that when I'm creating a new page, I always want that car image to appear on the right hand side by default. So whenever I'm changing the homepage car image to some other image, it should reflect on other pages also.
I'm just unable implement this requirement, how to go about it?
We have one custom requirement that when we add an image (suppose a car image) in the homepage, after that when I'm creating a new page, I always want that car image to appear on the right hand side by default. So whenever I'm changing the homepage car image to some other image, it should reflect on other pages also.
I'm just unable implement this requirement, how to go about it?
You require Advanced Custom Fields. Install the plugin in your site.
Advanced Custom Fields
Read the above documentation. Create a image upload field and use the field in both front-page.php and content-page.php
I suppose you are talking about featured image functionality?
In technical terms the featured image is attachment and post “knows” about it by its ID being stored in post meta. There is a pretty straightforward function get_post_thumbnail_id()
to retrieve that ID for specific post.
It is slightly trickier to have it attached to new posts by default. There is a get_default_post_to_edit()
function that handles defaults, but it mostly deals with text of the post. Personally I have used default_content
filter in it to assign custom fields, using second $post
argument passed to it. It's not too technically “correct” I suppose, but it makes semantic sense to me and I am not aware of better suited hook.
the easiest way would be to use the plugin advanced custom fields. with this you could create an options page where you can register a buld field.
otherwise you could create your own option pages with your own meta fields e.g. like here