- This topic has 19 replies, 3 voices, and was last updated 3 years, 11 months ago by Tom.
-
AuthorPosts
-
May 13, 2020 at 4:17 pm #1283336Mitch and Justine
Hi,
We are trying to add the total cost of recipes and cost per serving right below our H1 in single blog posts, but above the breadcrumbs.
We want it to look similar to this blog: https://www.budgetbytes.com/vegetable-barley-soup/. We found this code by inspecting the website, but are not sure how to add it, how to change the color, and how to change the font.
Here is the code we found:
<div class="post-meta"> <span class="cost">$6.67 recipe / $1.11 serving</span></div>
Thanks in advance,
Justine and MitchMay 14, 2020 at 3:22 am #1283786DavidStaffCustomer SupportHi there,
You can try following these steps:
1. Create a Custom Field in your Post editor:
https://wordpress.org/support/article/custom-fields/
1.1 For the example give the field a Name of
cost
and put in your value eg.$6.67 recipe / $1.11 serving
2. Now create a Hook Element in Appearance > Elements:
https://docs.generatepress.com/article/hooks-element-overview/
2.1 Add this code to the content:
<?php $cost = get_post_meta( get_the_ID(), 'cost', true ); if ( $cost ) { echo '<span class="recipe-cost">' . $cost . '</span>'; } ?>
2.2 Select
after_entry_title
from the Hook List.
2.3 Check execute PHP.
2.4 Set the Display Rules toPost > All Posts
– i am assuming you’re using Posts for your recipes
2.5 Publish your hook.3. Now we can use the
recipe-cost
class in our CSS:.recipe-cost { display: block; font-size: 16px; font-weight: 400; color: orange; }
May 15, 2020 at 8:53 am #1285895Mitch and JustineI’ve done everything, except add in the CSS code. Where do I add that in? Do I add it in from the main customization panel, or in each individual post?
May 15, 2020 at 9:11 am #1285943DavidStaffCustomer SupportYou can add that once in Customizer > Additional CSS
May 16, 2020 at 10:52 am #1287570Mitch and JustineOkay we followed all those steps, but it’s not working still.
May 16, 2020 at 2:59 pm #1287818TomLead DeveloperLead DeveloperHi there,
Can you show us a screenshot of the custom field filled out in the back-end of the post so we can make sure it all looks right?
May 18, 2020 at 8:21 pm #1291095Mitch and JustineOkay. How do I send a screenshot on here?
May 19, 2020 at 2:35 am #1291457DavidStaffCustomer SupportSave the screen shot to your Media Library or cloud/share drive and then share with us the URL to the image
May 19, 2020 at 7:37 am #1291921Mitch and JustineMay 19, 2020 at 8:56 am #1292245DavidStaffCustomer SupportLooks ok.
For the Hook content code can you try this instead temporarily:<p>If you see this then the hook is working</p> <?php $cost = get_post_meta( get_the_ID(), 'cost', true ); echo '<span class="recipe-cost">' . $cost . '</span>'; ?>
May 19, 2020 at 9:03 am #1292259Mitch and JustineOkay, so the “if you see this then the hook is working” is showing up now!. But how do we change it to be individual prices for each post?
May 19, 2020 at 10:23 am #1292415DavidStaffCustomer SupportSilly question … when you added the Custom field did you click the Add Custom Field afterwards ?
May 19, 2020 at 1:18 pm #1292630Mitch and JustineI did, yes
May 19, 2020 at 4:26 pm #1292859DavidStaffCustomer SupportAaah i think its because the Custom Field is case sensitive.
Can you edit the custom field name. Change it fromCost
tocost
and hit update.May 20, 2020 at 10:59 am #1294254Mitch and JustineOkay, that worked! Thanks so much. How can we also change the font size, weight, and color? We want it in #ff6060 and bolded.
-
AuthorPosts
- You must be logged in to reply to this topic.