Hi all,
I'm new here, I just require a (most likely simple for you lot) little help with editing some PHP code...
I am editing a WordPress child themes functions.php file, basically I want to get the logo image alt text to be generated per page by the pages title, I have sucessfully achieved this on some other sites with different themes but am having issues here.
This works in some themes:
alt="<?php echo the_title(); ?> keyword keyword"/>
So I need to include this:
alt="<?php echo the_title(); ?> keyword keyword"/>
Or this:
[show_post_categories show=”title”]
Into this, replacing the site_title in the alt= parts:
// LOGO CODE FOR SORTING ALT TEXT
<!-- Header logo -->
<a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?><?php echo get_bloginfo( 'name' ) && get_bloginfo( 'description' ) ? ' - ' : ''; ?><?php bloginfo( 'description' ); ?>" rel="home">
<?php if(flatsome_option('site_logo')){
$logo_height = get_theme_mod('header_height',90);
$logo_width = get_theme_mod('logo_width', 200);
$site_title = esc_attr( get_bloginfo( 'name', 'display' ) );
if(get_theme_mod('site_logo_sticky')) echo '<img width="'.$logo_width.'" height="'.$logo_height.'" src="'.get_theme_mod('site_logo_sticky').'" class="header-logo-sticky" alt="'.$site_title.'"/>';
echo '<img width="'.$logo_width.'" height="'.$logo_height.'" src="'.flatsome_option('site_logo').'" class="header_logo header-logo" alt="'.$site_title.'"/>';
if(!get_theme_mod('site_logo_dark')) echo '<img width="'.$logo_width.'" height="'.$logo_height.'" src="'.flatsome_option('site_logo').'" class="header-logo-dark" alt="'.$site_title.'"/>';
if(get_theme_mod('site_logo_dark')) echo '<img width="'.$logo_width.'" height="'.$logo_height.'" src="'.get_theme_mod('site_logo_dark').'" class="header-logo-dark" alt="'.$site_title.'"/>';
} else {
bloginfo( 'name' );
}
?>
</a>
<?php
if(get_theme_mod('site_logo_slogan')){
echo '<p class="logo-tagline">'.get_bloginfo('description').'</p>';
}
?>
THIS IS THE WHOLE FUNCTIONS.PHP FILE IN MY CHILD THEME:
<?php
// Add custom Theme Functions here
/**
* Change text strings
*
* @link http://codex.wordpress.org/Plugin_API/Filter_Reference/gettext
*/
function custom_related_products_text( $translated_text, $text, $domain ) {
switch ( $translated_text ) {
case 'Related products' :
$translated_text = __( 'More fire & security systems you may like', 'woocommerce' );
break;
}
return $translated_text;
}
add_filter( 'gettext', 'custom_related_products_text', 20, 3 );
/* USE SHORTCODES IN WIDGET TITLES AND PAGE TITLES !! */
add_filter('the_title', 'do_shortcode');
add_filter('widget_title', 'do_shortcode');
/* NOT SURE WHY I HAD THIS HERE??... <?php echo do_shortcode("[shortcode]"); ?> */
/* ADD ALT TAG TO GRAVATAR - BLOG-AUTHOR-IMAGE - IMAGES */
function crunchify_gravatar_alt($crunchifyGravatar) {
if (have_comments()) {
$alt = get_comment_author();
}
else {
$alt = get_the_author_meta('display_name');
}
$crunchifyGravatar = str_replace('alt=\'\'', 'alt=\'Avatar for ' . $alt . '\' title=\'Gravatar for ' . $alt . '\'', $crunchifyGravatar);
return $crunchifyGravatar;
}
add_filter('get_avatar', 'crunchify_gravatar_alt');
// LOGO CODE FOR SORTING ALT TEXT
<!-- Header logo -->
<a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?><?php echo get_bloginfo( 'name' ) && get_bloginfo( 'description' ) ? ' - ' : ''; ?><?php bloginfo( 'description' ); ?>" rel="home">
<?php if(flatsome_option('site_logo')){
$logo_height = get_theme_mod('header_height',90);
$logo_width = get_theme_mod('logo_width', 200);
$site_title = esc_attr( get_bloginfo( 'name', 'display' ) );
if(get_theme_mod('site_logo_sticky')) echo '<img width="'.$logo_width.'" height="'.$logo_height.'" src="'.get_theme_mod('site_logo_sticky').'" class="header-logo-sticky" alt="'.$site_title.'"/>';
echo '<img width="'.$logo_width.'" height="'.$logo_height.'" src="'.flatsome_option('site_logo').'" class="header_logo header-logo" alt="'.$site_title.'"/>';
if(!get_theme_mod('site_logo_dark')) echo '<img width="'.$logo_width.'" height="'.$logo_height.'" src="'.flatsome_option('site_logo').'" class="header-logo-dark" alt="'.$site_title.'"/>';
if(get_theme_mod('site_logo_dark')) echo '<img width="'.$logo_width.'" height="'.$logo_height.'" src="'.get_theme_mod('site_logo_dark').'" class="header-logo-dark" alt="'.$site_title.'"/>';
} else {
bloginfo( 'name' );
}
?>
</a>
<?php
if(get_theme_mod('site_logo_slogan')){
echo '<p class="logo-tagline">'.get_bloginfo('description').'</p>';
}
?>
I just can't get it to work, keeps throwing errors on save :(
I know this is just a silly newbies error - any assistance would be greatly appreciated.