• Resolved Trinaa3

    (@orenlebbo)


    Hello,
    How can I edit the text on the “Leave a Comment” button on the bottom of the AMP page?
    Thanks

Viewing 7 replies - 1 through 7 (of 7 total)
  • @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.

    Plugin Author Weston Ruter

    (@westonruter)

    @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.

    Thread Starter Trinaa3

    (@orenlebbo)

    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 4 years, 11 months ago by James Osborne.
    Thread Starter Trinaa3

    (@orenlebbo)

    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; ?>
    Plugin Author Weston Ruter

    (@westonruter)

    @orenlebbo Actually, /wp-content/themes/amp is not correct. It should be an amp 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.

    Thread Starter Trinaa3

    (@orenlebbo)

    Yes it’s working well now.
    Thank you!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Edit “Leave a Comment” text’ is closed to new replies.