admin管理员组

文章数量:1022736

I'm having an issue adding a dynamic site name/title to the footer with my Genesis theme. From their shortcode reference I've gathered that I should, I think, be able to add it in the below code in place of the Editable Link. Here's what I mean:

//* Change the footer text
add_filter('genesis_footer_creds_text', 'sp_footer_creds_filter');
function sp_footer_creds_filter( $creds ) {
    $creds = '[footer_copyright] <a href="/">Editable Link</a>';
    return $creds;
}

However, when I replace the Editable Link text with something like $creds = '[footer_copyright] <?php echo get_bloginfo( 'name' ); ?>'; I get:

Your PHP code changes were rolled back due to an error on line 291 of file wp-content/themes/genesis-sample-develop/functions.php. Please fix and try saving again.

syntax error, unexpected 'name' (T_STRING)

I've tried several variations of <?php echo get_bloginfo( 'name' ); ?> but nothing seems to want to work. What am I missing?

I'm having an issue adding a dynamic site name/title to the footer with my Genesis theme. From their shortcode reference I've gathered that I should, I think, be able to add it in the below code in place of the Editable Link. Here's what I mean:

//* Change the footer text
add_filter('genesis_footer_creds_text', 'sp_footer_creds_filter');
function sp_footer_creds_filter( $creds ) {
    $creds = '[footer_copyright] <a href="/">Editable Link</a>';
    return $creds;
}

However, when I replace the Editable Link text with something like $creds = '[footer_copyright] <?php echo get_bloginfo( 'name' ); ?>'; I get:

Your PHP code changes were rolled back due to an error on line 291 of file wp-content/themes/genesis-sample-develop/functions.php. Please fix and try saving again.

syntax error, unexpected 'name' (T_STRING)

I've tried several variations of <?php echo get_bloginfo( 'name' ); ?> but nothing seems to want to work. What am I missing?

Share Improve this question asked Apr 19, 2019 at 22:52 anonymooseanonymoose 1156 bronze badges 3
  • 1 That indeed contains a syntax error. You should use concatenation like so: '[footer_copyright] ' . get_bloginfo( 'name' ); – Sally CJ Commented Apr 19, 2019 at 23:39
  • 1 Worked like a charm, thank you. If you post that as an answer I'll accept it! Cheers – anonymoose Commented Apr 20, 2019 at 4:24
  • 1 I've done that. :) – Sally CJ Commented Apr 20, 2019 at 4:59
Add a comment  | 

1 Answer 1

Reset to default 1

Your code indeed contains a syntax error, which is unescaped quotes:

$creds = '[footer_copyright] <?php echo get_bloginfo( 'name' ); ?>';   // bad - ' not escaped
$creds = '[footer_copyright] <?php echo get_bloginfo( \'name\' ); ?>'; // good - ' escaped

But even if you escape the quotes, the code will not work as expected.

So to make it work as expected, use concatenation like so:

$creds = '[footer_copyright] ' . get_bloginfo( 'name' );

I'm having an issue adding a dynamic site name/title to the footer with my Genesis theme. From their shortcode reference I've gathered that I should, I think, be able to add it in the below code in place of the Editable Link. Here's what I mean:

//* Change the footer text
add_filter('genesis_footer_creds_text', 'sp_footer_creds_filter');
function sp_footer_creds_filter( $creds ) {
    $creds = '[footer_copyright] <a href="/">Editable Link</a>';
    return $creds;
}

However, when I replace the Editable Link text with something like $creds = '[footer_copyright] <?php echo get_bloginfo( 'name' ); ?>'; I get:

Your PHP code changes were rolled back due to an error on line 291 of file wp-content/themes/genesis-sample-develop/functions.php. Please fix and try saving again.

syntax error, unexpected 'name' (T_STRING)

I've tried several variations of <?php echo get_bloginfo( 'name' ); ?> but nothing seems to want to work. What am I missing?

I'm having an issue adding a dynamic site name/title to the footer with my Genesis theme. From their shortcode reference I've gathered that I should, I think, be able to add it in the below code in place of the Editable Link. Here's what I mean:

//* Change the footer text
add_filter('genesis_footer_creds_text', 'sp_footer_creds_filter');
function sp_footer_creds_filter( $creds ) {
    $creds = '[footer_copyright] <a href="/">Editable Link</a>';
    return $creds;
}

However, when I replace the Editable Link text with something like $creds = '[footer_copyright] <?php echo get_bloginfo( 'name' ); ?>'; I get:

Your PHP code changes were rolled back due to an error on line 291 of file wp-content/themes/genesis-sample-develop/functions.php. Please fix and try saving again.

syntax error, unexpected 'name' (T_STRING)

I've tried several variations of <?php echo get_bloginfo( 'name' ); ?> but nothing seems to want to work. What am I missing?

Share Improve this question asked Apr 19, 2019 at 22:52 anonymooseanonymoose 1156 bronze badges 3
  • 1 That indeed contains a syntax error. You should use concatenation like so: '[footer_copyright] ' . get_bloginfo( 'name' ); – Sally CJ Commented Apr 19, 2019 at 23:39
  • 1 Worked like a charm, thank you. If you post that as an answer I'll accept it! Cheers – anonymoose Commented Apr 20, 2019 at 4:24
  • 1 I've done that. :) – Sally CJ Commented Apr 20, 2019 at 4:59
Add a comment  | 

1 Answer 1

Reset to default 1

Your code indeed contains a syntax error, which is unescaped quotes:

$creds = '[footer_copyright] <?php echo get_bloginfo( 'name' ); ?>';   // bad - ' not escaped
$creds = '[footer_copyright] <?php echo get_bloginfo( \'name\' ); ?>'; // good - ' escaped

But even if you escape the quotes, the code will not work as expected.

So to make it work as expected, use concatenation like so:

$creds = '[footer_copyright] ' . get_bloginfo( 'name' );

本文标签: Issue echoing the site39s title in Genesis child theme