Site logo

Archived topic

How to add custom fields (meta data) to posts on home page and archive pages?

11 replies · Started by sampath on December 21, 2017

Viewing posts 1–12 of 12

Hey, I am new to wordpress(php) development. I have purchased generatepress plugin recently. I was able to modify single posts page successfully to my requirement.

1. I have some meta data as custom fields for each post, I am trying to add this meta data to the posts on the home page instead of date, author, category meta data.

2. I also want to style or change the post format to my requirement. Does changing css will be enough and right way to do it?>

I am not able to find the right place to add it. look like post-meta.php is the right place but i need more help: whats the right way to add and where ?

Thanks in advance

hey thanks, overriding generate_post_meta function to add custom meta data to posts on homepage worked, but as soon as i enabled 'blog' from the GP plugin my changes are gone???

You shouldn't need to override anything - you can just create your own fresh function and insert it into that hook.

Yeah, adding a new function to the hook works too!
Also, i found out why my meta data is not showing when i enable 'blog', its because i have unchecked 'display post data, author, categories, tags' and its hiding my custom meta data too with a css style - display: none.

How do I show my custom meta with the 'blog' activated from the GP Plugin.

I really appreciate your support Tom.

changing the div class name from entry-meta to someother class worked.

Thanks

Glad you got it working! You can also just override that display: none CSS to display: block with an !important or a more specific selector :)

okay thanks
When I add a css class to a div element I am seeing the same class in both homepage and single page.

Is there a way to apply css class only to homepage elements??
I was modifying 'generate_post_classes' and 'generate_main_classes' functions
Thanks

You would just add .home at the start of the selector.

For example, .inside-article would be .home .inside-article

i am trying to add bootstrap column class to article element i.e 'col-lg-4 col-sm-6 col-xs-6' but they are being applied to both home posts and single posts page.

your solution might not be helpful in this case

edit: also i did not find any .home class already in there, did you mean to 'add a new .home class to inside-article element and style it'?

Glad you got it working :)

This archived topic is closed to new replies.