• Resolved lorenzo

    (@ramboelmeio)


    Hello, i need help for a simple question i think.
    I’d like to change the text and url of the button keyboard.

    I know i would put some code into the funchtion.php and use the wptelegram_p2tg_inline_keyboard filter but i tried some times but i am not able to.

    i just need to replace the code:

    $default_button = array(
    	'text' => '🔗 ' . $inline_button_text,
    	'url'  => self::$post_data->get_field( 'full_url' ),
    	);

    with this to solve my problem

    $default_button = array(
    'text' => '🔗 ' . 'INFO',
      'url'  => 'https://t.me/mytelegramuser',
      );

    but i don’t know how to get it without editing the plugin code directly

    the compete function in your code is this

    public function get_inline_keyboard( $method_params ) {
    
    $inline_url_button  = $this->options->get( 'inline_url_button' );
    $inline_button_text = $this->options->get( 'inline_button_text' );
    
    if ( 'on' !== $inline_url_button ) {
        return false;
    }
    
    $default_button = array(
         'text' => '🔗 ' . $inline_button_text,
         'url'  => self::$post_data->get_field( 'full_url' ),
    );
    		
    $default_button = (array) apply_filters( 
    'wptelegram_p2tg_default_inline_button', $default_button, self::$post,                 $method_params );
    
    $inline_keyboard[][] = $default_button;
    
    return (array) apply_filters( 'wptelegram_p2tg_inline_keyboard', 
    $inline_keyboard, self::$post, $method_params );
    }

    How do i apply a filter to edit $default_button array in my functions.php?

    Thanks so much for your work and your support

    • This topic was modified 6 years, 1 month ago by lorenzo.
    • This topic was modified 6 years, 1 month ago by lorenzo.
    • This topic was modified 6 years, 1 month ago by lorenzo.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Here is the custom code you can use

    /* WPTelegram Modify default inline button */
    add_filter( 'wptelegram_p2tg_default_inline_button', function ( $button, $post ) {
    
    	// set the URL of your choice
    	$button['url'] = 'https://t.me/mytelegramuser';
    	
    	$button['text'] = '🔗 ' . 'INFO';
    
    	return $button;
    	
    }, 10, 2 );
    /* WPTelegram Modify default inline button */

    Note: You should never modify plugin files, rather you should add the custom code to your active/child theme.

    Thread Starter lorenzo

    (@ramboelmeio)

    thank you very much!It works!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘edit inline keyboard button’ is closed to new replies.