php 过滤WordPress自定义徽标

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 过滤WordPress自定义徽标相关的知识,希望对你有一定的参考价值。

<?php
// Enable custom logo support
// https://codex.wordpress.org/Theme_Logo
add_theme_support( 'custom-logo' );
<header class="banner navbar navbar-inverse navbar-static-top" role="banner">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
        <span class="sr-only"><?= __('Toggle navigation', 'sage'); ?></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <?php the_custom_logo(); ?>
    </div>

    <nav class="collapse navbar-collapse" role="navigation">
      <?php
      if (has_nav_menu('primary_navigation')) :
        wp_nav_menu(['theme_location' => 'primary_navigation', 'menu_class' => 'nav navbar-nav']);
      endif;
      ?>
    </nav>
  </div>
</header>
<?php
/**
 * Site Brand
 *
 * Output site branding
 *
 * Use native WordPress site logo with custom (bootstrap friendly) markup
 * Falls back to text title if logo is not set.
 *
 * @param $html
 *
 * @return string
 */
function siteBrand($html)
{
  // grab the site name as set in customizer options
  $site = get_bloginfo('name');
  // Wrap the site name in an H1 if on home, in a paragraph tag if not.
  is_front_page() ? $title = '<h1>' . $site . '</h1>' : $title = '<p>' . $site . '</p>';
  // Grab the home URL
  $home = esc_url(home_url('/'));
  // Class for the link
  $class = 'navbar-brand';
  // Set anchor content to $title
  $content = $title;
  // Check if there is a custom logo set in customizer options...
  if (has_custom_logo()) {
    // get the URL to the logo
    $logo    = wp_get_attachment_image(get_theme_mod('custom_logo'), 'full', false, array(
      'class'    => 'brand-logo img-responsive',
      'itemprop' => 'logo',
    ));
    // we have a logo, so let's update the $content variable
    $content = $logo;
    // include the site name markup, hidden with screen reader friendly styles
    $content .= '<span class="sr-only">' . $title . '</span>';
  }
  // construct the final html
  $html = sprintf('<a href="%1$s" class="%2$s" rel="home" itemprop="url">%3$s</a>', $home, $class, $content);

  // return the result to the front end
  return $html;
}

add_filter('get_custom_logo', __NAMESPACE__ . '\\siteBrand');

以上是关于php 过滤WordPress自定义徽标的主要内容,如果未能解决你的问题,请参考以下文章

PHP Wordpress - 自定义WordPress登录页面的徽标

php 检索自定义徽标wordpress

php 自定义徽标WordPress登录

php 自定义徽标WordPress登录

PHP 自定义WordPress登录页面的徽标

PHP Wordpress自定义管理员徽标