Community Forums › Forums › Archived Forums › Design Tips and Tricks › Conditional Statement Not Working to Change Site Title on Blog Page
Tagged: conditional statement, site title
- This topic has 5 replies, 2 voices, and was last updated 9 years, 1 month ago by Brad West.
-
AuthorPosts
-
March 11, 2015 at 3:22 am #143979Brad WestMember
I'm trying to change the site-title text for my blog page. Any ideas why the below isn't working?
http://www.thelifechangepeople.com/blog/add_action( 'genesis_site_title', 'lifechange_blog_title' ); function lifechange_blog_title() { if ( is_page( 'blog' ) ) { add_filter( 'genesis_seo_title', 'custom_genesis_seo_title', 10, 1 ); function custom_genesis_seo_title( $title ) { $title = '<h1 itemprop="headline" class="site-title">The Life Change Blog</h1>'; return $title; } } }
March 11, 2015 at 4:50 am #143988Brad DaltonParticipantYou could create a custom blog page template and use code in it as the conditional may not always work on the blog page template.
Rather than filter it, you can then simply remove the default and add back a new one.
Otherwise, try the filter in your functions file and play around with the conditional:
add_filter( 'genesis_seo_title', 'custom_genesis_seo_title', 10, 1 ); function custom_genesis_seo_title( $title ) { if ( is_your_conditional() ) { $title = '<h1 itemprop="headline" class="site-title">The Life Change Blog</h1>'; return $title; } }
March 11, 2015 at 8:57 pm #144117Brad WestMemberI've tried creating a blog template, but I couldn't get it to work. First it doesn't change the title, but worse it doesn't display any blog posts. Do you know of any tutorials for this?
As for the conditional, the one above is in the functions file, but I can't get it to work. I tried is_page( 'blog' ), is_page( 'The Life Change Blog' ), is_page( 27 ), is_singular( 'blog' ), is_singular( 'The Life Change Blog' ) and is_singular( 27 ). None of these work. I've also tried hooking it in different places: add_action( 'genesis_site_title', 'lifechange_blog_title' );, add_action( 'genesis_seo_title', 'lifechange_blog_title' ); and add_action( 'genesis_header', 'lifechange_blog_title' );. None of this makes any difference either.
March 11, 2015 at 9:47 pm #144119Brad DaltonParticipantI do have several tutorials on these topics for members only http://wpsites.net/web-design/add-content-before-posts-blog-page-only/
March 11, 2015 at 10:29 pm #144121Brad WestMemberI found some discussion on StackExchange that was helpful. I decided to try again with the Blog Template, and used the below. It's working for me.
<?php /** Template Name: Life Change Blog */ //* Replace Site Title text add_filter( 'genesis_seo_title', 'custom_genesis_seo_title', 10, 1 ); function custom_genesis_seo_title( $title ) { $title = "<h1 itemprop='headline' class='site-title'>The Life Change Blog</h1>"; return $title; } //* Replace the loop. remove_action( 'genesis_loop', 'genesis_do_loop' ); add_action( 'genesis_loop', 'genesis_custom_loop' ); //* Change the content archive and loop args. add_action( 'genesis_pre_get_option_content_archive', 'child_post_content_archive' ); add_filter( 'genesis_custom_loop_args', 'child_loop_args' ); genesis(); //* Change default content to excerpts on this page. function child_post_content_archive() { return 'excerpts'; } /** * Use WP_Query args. * * @link {http://codex.wordpress.org/Function_Reference/WP_Query} */ function child_loop_args() { return array( posts_per_page => 5, ); }
March 11, 2015 at 10:30 pm #144122Brad WestMemberAlthough, if someone can explain why that conditional in the original post isn't working, I'd love to know.
-
AuthorPosts
- The topic ‘Conditional Statement Not Working to Change Site Title on Blog Page’ is closed to new replies.