Edit “Leave a Comment” text
-
Hello,
How can I edit the text on the “Leave a Comment” button on the bottom of the AMP page?
Thanks
-
@orenlebbo Can you try the below, which uses the gettext filer. You will need to add this to the functions.php file of your active theme:
add_filter( 'gettext', 'replace_comments_text', 10, 3 ); function replace_comments_text( $translation, $text, $domain ){ if( $text === 'Leave a Comment' ) { $text = 'Comments'; } return $text; }
Let me know if that works for you.
@jamesosborne It would be preferable to override the Reader mode template rather than use the filter. This is because this filter is applied many many times, and thus it would have more of a performance impact.
Hello,
Isn’t there a permanent fix that will save me and others the need to re-add this code to the functions.php after every WP version update?
Can’t you add a field in the plugin’s settings that will let me and others edit this small piece of text?
Thanks again,
Thanks for the tip @westonruter.
@orenlebbo Can you create a folder called “amp” within your active themes directory. Within that folder you can place the “meta-comments-link.php” file. You can copy it from the wp-content/plugins/amp/templates or just add the following code to the file, replacing the <?php echo esc_html( $comments_link_text ); ?> code below with your own text replacement.
<?php /** * Post comments link template part. * * @package AMP */ $comments_link_url = $this->get( 'comments_link_url' ); ?> <?php if ( $comments_link_url ) : ?> <?php $comments_link_text = $this->get( 'comments_link_text' ); ?> <div class="amp-wp-meta amp-wp-comments-link"> <a href="<?php echo esc_url( $comments_link_url ); ?>"> <?php echo esc_html( $comments_link_text ); ?> </a> </div> <?php endif; ?>
Let me know if that works for you.
-
This reply was modified 5 years, 7 months ago by
James Osborne.
I created the folder under /wp-content/themes/amp
Into it I copied the file you mentioned, with the changing of the line with the text.
Unfortunately it doesn’t work..
knb.is
This is what in my file:
<?php /** * Post comments link template part. * * 🚫🚫🚫 * DO NOT EDIT THIS FILE WHILE INSIDE THE PLUGIN! Changes You make will be lost when a new version * of the AMP plugin is released. You need to copy this file out of the plugin and put it into your * custom theme, for example. To learn about how to customize these Reader-mode AMP templates, please * see: https://amp-wp.org/documentation/how-the-plugin-works/classic-templates/ * 🚫🚫🚫 * * @package AMP */ $comments_link_url = $this->get( 'comments_link_url' ); ?> <?php if ( $comments_link_url ) : ?> <?php $comments_link_text = $this->get( 'comments_link_text' ); ?> <div class="amp-wp-meta amp-wp-comments-link"> <a href="<?php echo esc_url( $comments_link_url ); ?>"> תגובות </a> </div> <?php endif; ?>
@orenlebbo Actually,
/wp-content/themes/amp
is not correct. It should be anamp
directory under your active theme. So if you are using a theme “Foo” the file should be located in a directory/wp-content/themes/foo/amp
. Also, please remove the “🚫🚫🚫” warning comment in your theme template override, because that is only to warn against modifying the template file in the plugin.This assumes you have a custom theme and that you aren’t modifying a theme that you are updating from WordPress.org.
Yes it’s working well now.
Thank you! -
This reply was modified 5 years, 7 months ago by
- The topic ‘Edit “Leave a Comment” text’ is closed to new replies.