需要打印不带任何ID和类别的徽标

时间:2016-12-29 作者:apasajja

在里面functions.php:

function mymy_setup() {
    // Add theme support for Custom Logo.
    add_theme_support( \'custom-logo\', array(
        \'width\'       => 80,
        \'height\'      => 40,
        \'flex-width\'  => true,
    ) );
}
add_action( \'after_setup_theme\', \'mymy_setup\' );
在模板中:

<?php the_custom_logo(); ?>
HTML输出:

<a href="http://localhost/myweb/" class="custom-logo-link" rel="home" itemprop="url"><img width="80" height="40" src="http://localhost/myweb/wp-content/uploads/2016/12/cropped-cropped-1-2.jpg" class="custom-logo" alt="" itemprop="logo" /></a>
我需要的是:

<a href="http://localhost/myweb/"><img src="http://localhost/myweb/wp-content/uploads/2016/12/cropped-cropped-1-2.jpg" /></a>
如何在没有任何ID的情况下打印(&A);班(我也只能接受打印徽标URL)

1 个回复
最合适的回答,由SO网友:Tunji 整理而成

您可以使用get_custom_logo 滤器

add_filter( \'get_custom_logo\', \'wpse250683_custom_logo_output\' );

function wpse250683_custom_logo_output() {
    $custom_logo_id = get_theme_mod( \'custom_logo\' );
    $attachment     = wp_get_attachment_image_src( $custom_logo_id, \'full\', false );
    $attachment_url = \'\';
    if ( is_array( $attachment ) )
        $attachment_url = $attachment[0];
    $html = sprintf( \'<a href="%1$s"><img src="%2$s" /></a>\',
        esc_url( home_url( \'/\' ) ),
        $attachment_url
    );
    return $html;
}

相关推荐

og:image functions.php

我有自定义模板,我需要得到og:在标题图像url。类映像在DB wp\\u postmeta-meta\\u value中的位置我尝试使用函数。phpfunction getOgImage() { global $wpdb; $ogimage = $wpdb->get_results(\"SELECT DISTINCT post_id FROM wp_postmeta WHERE meta_value\", OBJECT); echo