Tagged: Customizing default behavior, footer, hook, jumpstart
Default Footer Cutomization
-
CreatorTopic
-
July 5, 2014 at 2:27 pm #17621
Matthew MacMillan
ParticipantHi all,
In an effort to continue learning how to take full control of my child themes, I’m trying to learn how to control the default content in a JumpStart. I’m well and truly stumped. It took about… 7 minutes. (Though I’ve been rooting around, trying to figure it out myself for about 2 days).
For the sake of example, I’ll use JumpStart’s default footer copy: (“class-tb-options-api.php”, line 309)
'footer_copyright' => array( 'name' => __( 'Footer Copyright Text', 'themeblvd' ), 'desc' => __( 'Enter the copyright text you\'d like to show in the footer of your site.', 'themeblvd' ), 'id' => 'footer_copyright', 'std' => '(c) '.date('Y').' '.get_bloginfo('site_title').' - Powered by <a href="http://wordpress.org" title="WordPress" target="_blank">WordPress</a>, Designed by <a href="http://themeblvd.com" title="Theme Blvd" target="_blank">Theme Blvd</a>', 'type' => 'text' )
How would I change this default from the child theme’s functions.php to say instead:
'footer_copyright' => array( 'name' => __( 'Footer Copyright Text', 'themeblvd' ), 'desc' => __( 'Enter the copyright text you\'d like to show in the footer of your site.', 'themeblvd' ), 'id' => 'footer_copyright', 'std' => '(c) '.date('Y').' '.get_bloginfo('site_title').' - Powered by <a href="http://wordpress.org" title="WordPress" target="_blank">WordPress</a>, Designed by <a href="http://themeblvd.com" title="Theme Blvd" target="_blank">Theme Blvd</a>, and Produced by <a href="http://matthewmacmillan.com" title="Matthew MacMillan" target="_blank">Matthew MacMillan</a>', 'type' => 'text' )
I’m not sure how exactly to hook in to this, because I’m seeing a bunch of private functions. Those are inaccessible, right? Forgive me if I sound like an complete greenhorn, I’m a front end developer, and PHP is still kind of a mystery to me. That’s why I’m doing this. 🙂
Any light your gurus can shed would be awesome. Thanks in advance!
Matt
-
CreatorTopic
-
AuthorReplies
-
July 5, 2014 at 7:13 pm #17624
Jason Bobich
KeymasterHi Matt,
It’s awesome you’re trying to extend your frontend dev skills!
In this particular case, if you checkout our API docs, for theme options, there’s a function
themeblvd_edit_option()
you could use:http://dev.themeblvd.com/tutorial_category/chapter-05/
http://dev.themeblvd.com/tutorial/add-remove-edit-theme-option/#themeblvd_edit_option
In this case, it would implement something like this:
$footer_default = '(c) '.date('Y').' '.get_bloginfo('site_title').' - Powered by <a href="http://wordpress.org" title="WordPress" target="_blank">WordPress</a>, Designed by <a href="http://themeblvd.com" title="Theme Blvd" target="_blank">Theme Blvd</a>, and Produced by <a href="http://matthewmacmillan.com" title="Matthew MacMillan" target="_blank">Matthew MacMillan</a>'; themeblvd_edit_option( 'layout', 'footer', 'footer_copyright', 'std', $footer_default );
And it might all be cleaner within your child theme, if you start organizing these items into functions like this:
/** * Theme Options mods */ function my_options() { // Change default footer option text $footer_default = '(c) '.date('Y').' '.get_bloginfo('site_title').' - Powered by <a href="http://wordpress.org" title="WordPress" target="_blank">WordPress</a>, Designed by <a href="http://themeblvd.com" title="Theme Blvd" target="_blank">Theme Blvd</a>, and Produced by <a href="http://matthewmacmillan.com" title="Matthew MacMillan" target="_blank">Matthew MacMillan</a>'; themeblvd_edit_option( 'layout', 'footer', 'footer_copyright', 'std', $footer_default ); // Continue doing any other option mods ... } add_action( 'after_setup_theme', 'my_options' );
======
This example is a little complex because it’s all setup around making these API functions possible. But just in general, if you’re hunting around and trying to manipulate data, you want to look for filters. Scattered throughout everywhere you’re going to see where a piece of data has apply_filters() wrapped around it; this means it’s being passed through a filter which you can then have access to.
http://dev.themeblvd.com/tutorial/filters/
Even in this example of the theme options, if you had gone all the way down to the bottom
set_raw_options()
you’d see that this giant array is wrapped in a filter “themeblvd_core_options” — You could technically filter onto this, as well, as long as you did before the framework ran in your child theme.function my_core_options( $options ) { $options['layout]['sections']['footer']['options']['footer_copyright']['std'] = 'Your new value...'; return $options; } add_filter( 'themeblvd_core_options', 'my_core_options' );
…. but like I said, this particular situation is a bit complex with a lot of moving parts and a gigantic array, which is why create those API functions people can use. 😉
July 7, 2014 at 11:19 am #17645Matthew MacMillan
ParticipantThis is awesome. Jason you continue to be a guiding star in my learning process. Thanks, man!
I’m sure I will be filling this page with question as soon as my coffee kicks in. 🙂
Matt -
AuthorReplies
- You must be logged in to reply to this topic.