Replacing View Post Text

Hi, I have added this to my functions.php and I am hoping to replace the ‘View Post’ text with the place icon… can you tell me what I am doing wrong?

// Alternate Text

function alternate_text( $translated_text, $text, $domain ) {
switch ( $translated_text ) {
case ‘View Post’ :
$translated_text = __( ‘[x_icon type=“play”]Your Custom View Post Text’, ‘x’ );
break;
}
return $translated_text;
}
add_filter( ‘gettext’, ‘alternate_text’, 20, 3 );
//

Hello There,

Thanks for posting in!

Simply update your code and use this instead:

// Alternate Text
function alternate_text( $translated_text, $text, $domain ) {
	$translated = str_ireplace('View Post', 'insert your translation here', $translated);
  	return $translated; 
}
add_filter( 'gettext', 'alternate_text');
//

And please do not forget to insert your translation.

Thanks for this… I am trying to add an icon in as a text replacement but its not working… I am assuming it needs an echo statement?

// Alternate Text
function alternate_text( $translated_text, $text, $domain ) {
$translated = str_ireplace(‘View Post’, ‘[x_icon type=“play-circle”]’, $translated);
return $translated;
}
add_filter( ‘gettext’, ‘alternate_text’);
//

Hello There,

Shortcodes do not work out of the box. You may need something like this:


// Alternate Text
function alternate_text( $translated_text, $text, $domain ) {
  $translated = str_ireplace('View Post', '<i class="x-icon x-icon-play-circle" data-x-icon-s="&#xf144" aria-hidden="true"></i>', $translated);
  return $translated; 
}
add_filter( 'gettext', 'alternate_text');
//

or at least must add $icon = do_shortcode('[x_icon type="play-circle"]') and use the icon variable as a replacement.

Hope this helps.

Hi,

Where would the declaration of the icon go? Also, since adding to functions.php my entire backend does not work :weary: … what can I do to rectify this?

Hi,

You need to login to ftp then navigate to wp-content/themes/x-child/functions.php
Download functions.php to your computer and edit it using text editor.

Please change the code to

// Alternate Text
function alternate_text( $translated_text, $text, $domain ) {
  $icon = do_shortcode('[x_icon type="play-circle"]')
  $translated = str_ireplace('View Post',$icon, $translated);
  return $translated; 
}
add_filter( 'gettext', 'alternate_text');
//

Hope that helps

Thanks - it is now returning a syntax error - Parse error: syntax error, unexpected ‘$translated’ (T_VARIABLE)

Hi,

Sorry about that.

Kindly change the code to this.

// Alternate Text
function alternate_text( $translated_text, $text, $domain ) {
  $icon = do_shortcode('[x_icon type="play-circle"]')
  $translated_text= str_ireplace('View Post',$icon, $translated_text);
  return $translated_text; 
}
add_filter( 'gettext', 'alternate_text');
//

Thanks

Hi, still getting this error…

Hello There,

There was a missing semi colon in the code.
Please have it updated and use this:

// Alternate Text
function alternate_text( $translated_text, $text, $domain ) {
  $icon = do_shortcode('[x_icon type="play-circle"]');
  $translated = str_ireplace('View Post',$icon, $translated);
  return $translated; 
}
add_filter( 'gettext', 'alternate_text');
//

Please let us know how it goes.

Hi, that hasnt worked either… broken the back end of the site (hidden all the menu text) icon still not displaying front end either.

Pic of broken back end.

Hey There,

​To assist you better with this issue, would you mind providing us the url of your site with login credentials so we can take a closer look? This is to ensure that we can provide you with a tailored answer to your situation. Once you have provided us with your URL, we will be happy to assist you with everything.

To do this, you can create a secure note with the following info:
– Link to your site
– WordPress Admin username / password

To know how to create a secure note, please check this out: https://theme.co/apex/forum/t/how-to-get-support/288

Thank you.

OK details attached. Thanks

Hello There,

I have logged in. Sorry it took me a while to noticed that there was a typographical error in the code. I already have updated it and used this:

// =============================================================================
// Alternate Text
function alternate_text( $translated_text ) {
  $icon = do_shortcode('[x_icon style="font-size: 26px;" type="play-circle"]');
  $translated = str_ireplace('View Post',$icon, $translated_text);	
  return $translated; 
}
add_filter( 'gettext', 'alternate_text');
// =============================================================================

If there is a need to increase the font size of the pay icon, feel free to increase it.

Please check your site now.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.