Community Forums › Forums › Archived Forums › Design Tips and Tricks › Custom field in footer
Tagged: custom field, footer
- This topic has 2 replies, 2 voices, and was last updated 8 years, 1 month ago by unklee.
-
AuthorPosts
-
March 20, 2016 at 4:42 am #181899unkleeMember
Hi,
I am using the Minimum Pro theme, and I want to put a custom field in the footer, so that I can have different text on every page (not on posts at all). I am almost there (I can get my custom field to appear just before the footer) but have two questions please:
1. To do this I have to enter code in the footer.php page (I think). But this file is in the Genesis folder and not in the Minimum Pro folder, and is clearly labelled not to be altered. Checking this out on the web I see the suggestion that I should copy the footer.php code into a new footer.php file in the Minimum Pro folder, then add the extra code here.
But this would mean that if the Genesis file is ever updated, nothing would change because the Minimum Pro file would override it, so I would have to keep aware of any update to the Genesis footer.php file and copy it into the Minimum Pro footer.php file. That doesn't seem to be a sensible course.
Is there a way to add the required code to Minimum pro without over-riding the Genesis footer.php file?
2. I have set up a new custom field so that I can select it in each page's edit page and enter the text I want. I have then added the following code to the new footer.php file under Minimum Pro:
global $post; if( is_object( $post ) ) { echo get_post_meta($post->ID, 'fieldname', true); }
This works, in that the text appears on the page, but it doesn't appear within the footer, but either above or below the footer (depending on where I place this code among the existing code) and it has no tags so I can't style it. How can I get it to appear within the footer, or at least within tags so I can style it?
Any help would be much appreciated please. My knowledge of WP and PHP is fairly basic.
March 20, 2016 at 5:29 am #181902Victor FontModeratorYou don't have to touch footer.php at all. Genesis has many, many hooks that allow you to modify code without touching the code. Here is a snippet that allows you to modify the footer: http://my.studiopress.com/snippets/footer/#custom-footer.
You can wrap your custom field in any css classes you'd like so you can style it.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?March 20, 2016 at 6:53 pm #181946unkleeMemberThanks Victor, that sent me off in the right direction. I knew about hooks, but didn't think of combining them with custom fields.
I wanted to place a different quote in the footer of each page, so just for the record, in case someone else reads this, here is what I did.
1. I created a new custom field named "quote" on one of the page edit pages, and this allows me to select the quote field on each page and enter the quote.
2. I created a new file named quote.php and put it in the Minimum Pro folder. It had the following code:
<?php global $post; echo get_post_meta($post->ID, 'quote', true); ?>
3. I inserted the following code in the Minimum Pro functions.php file:
add_action( 'genesis_before_footer', 'quote_field' ); function quote_field() { echo"<div class=\"quote\"> <div class=\"wrap\">"; require(CHILD_DIR.'/quote.php'); echo"</div></div>"; }
This was a bit tricky. I couldn't get the custom field to appear at the beginning of the footer as I wanted, so I chose to put it before the footer and then style it so it was identical to the footer. To get it to look right in Minimum Pro, I needed it inside a "quote" div and a "wrap" div, and using an echo before and after the quote.php file was called was the way I made that happen.
4. I then styled the div.quote to have the same background os the footer and to have the size text I wanted.
Thanks again. I learned a little more about WP and php through this little puzzle.
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.