Custom Theme – Using add_theme_support( ‘custom-logo’ )
-
I’ve been wracking my brain on this, and I can’t figure it out from the WP Documentation here.
I have custom form fields setup in a
functions.php
file. Basically, everything i’ve added there works properly, so I understand how to do that (e.g.
add_settings_section(), add_option(), add_settings_field(), register_setting()
)That stuff is pretty straightforward to me, but I don’t understand what’s supposed to be used for a custom logo, as my attempt to return values seems to be calling something that doesn’t exist.
From what I’ve read, it is NOT specified in the documentation. Have a look at the Theme Dev Handbook – Custom Logo page.
we haveadd_theme_support( 'custom-logo' );
, where there is a hyphen in “custom-logo”. It is shown under add_theme_support$feature
parameter as so also, with the hyphen. ‘custom-logo’. No where that I’ve read is it specified that this is the “correct” or required syntax, but I assume that is correct.However, my assumption is dispelled when the same page Theme Dev Handbook – Custom Logo ALSO references it as
$custom_logo_id = get_theme_mod( 'custom_logo' );
with an underscore custom_logo. It is not indicated if these are arbitrary symbols or required. Also, it is NOT indicated if required to use set_theme_mod(‘custom_logo’) prior to setting that mod (e.g. I don’t have to use set_theme_mod(‘address_field’) to add an address field, if i’ve done it like so:add_option('address_info'); add_settings_field("address_info", "Mailing Address", "jankyattempt_display_address_element", "theme_options", 'theme_settings_page');
I put var_dump’s in the functions.php to try to sort this out:
NOTE: line numbers marked as [012] in the source, to match the Xdebug output lines shown:function jankyattempt_test_custom_image() { if ( function_exists( 'the_custom_logo' ) ) { echo '<br>the_custom_logo() @line: '.__LINE__ . the_custom_logo(); } $custom_logo_id = get_theme_mod( 'custom_logo' ); $logo = wp_get_attachment_image_src( $custom_logo_id , 'full' ); if ( has_custom_logo() ) { [332] echo '<br>@line: '.__LINE__ .'<img src="' . esc_url( $logo[0] ) . '" alt="' . get_bloginfo( 'name' ) . '" />'; } else { echo '<h1>@line: '.__LINE__ . get_bloginfo('name') . '</h1>'; } [336] echo '<br>@line: '.__LINE__ .'<br>test has_custom_logo:' . has_custom_logo(); $custom_logo_id = get_theme_mod( 'custom_logo' ); $image = wp_get_attachment_image_src( $custom_logo_id , 'full' ); [339] echo '<br>Demo technique wp_get_attachment_image_src: <br>@line: '.__LINE__ .$logo[0]; // alt ver: [342] echo '<br>Demo technique wp_get_attachment_url:<br>@line: '.__LINE__ . esc_url( wp_get_attachment_url( get_theme_mod('custom_logo') ) ); [347] echo '<br>@line: '.__LINE__ . var_dump($logo); echo '<br>@line: '.__LINE__ .var_dump($custom_logo_id); echo '<br>@line: '.__LINE__ . var_dump(wp_get_attachment_url(get_theme_mod('custom_logo') )); echo '<br>@line: ' . __LINE__ .' get_theme_mod(custom_logo): '. get_theme_mod('custom_logo'); } add_action('admin_init', 'jankyattempt_test_custom_image');
I’m running around in the dark, shooting arrows in the air! So frustrating.
The output on my ./wp-admin/?custom-settings-page
@line: 332 Jankyattempt Sass2 @line: 336 test has_custom_logo:1 ( ! ) Notice: Trying to access array offset on value of type bool in /var/www/html/Jankyattempt/wp-content/themes/jankyattempt/functions.php on line 339 Call Stack # Time Memory Function Location 1 0.0001 383944 {main}( ) .../index.php:0 2 0.0001 384680 require_once( '/var/www/html/Jankyattempt/wp-admin/admin.php ) .../index.php:10 3 0.0868 3435936 do_action( $hook_name = 'admin_init' ) .../admin.php:175 4 0.0868 3436312 WP_Hook->do_action( $args = [0 => ''] ) .../plugin.php:517 5 0.0868 3436312 WP_Hook->apply_filters( $value = '', $args = [0 => ''] ) .../class-wp-hook.php:332 6 0.0901 3518232 Jankyattemptsass_test_custom_image( '' ) .../class-wp-hook.php:308 Demo technique wp_get_attachment_image_src: @line: 339 Demo technique wp_get_attachment_url: @line: 342 /var/www/html/Jankyattempt/wp-content/themes/jankyattempt/functions.php:347:boolean false @line: 347 /var/www/html/Jankyattempt/wp-content/themes/jankyattempt/functions.php:348:string 'default' (length=7) @line: 348 /var/www/html/Jankyattempt/wp-content/themes/jankyattempt/functions.php:349:boolean false @line: 349 @line: 350 get_theme_mod(custom_logo): default
Can someone please point me in the right direction? Something that has a more concrete example (than the official documentation)?
??Thank you!
- This topic was modified 1 year, 11 months ago by .
- This topic was modified 1 year, 11 months ago by .
The page I need help with: [log in to see the link]
- The topic ‘Custom Theme – Using add_theme_support( ‘custom-logo’ )’ is closed to new replies.