Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1318849
    sandrayin
    Participant

    Hi,

    How can I add a button (hyperlink to 1 url page) at the top and bottom of my content? I want to make sure the button is supported by WPML too. So far I have hardcoded it in the php using a child theme. Not a good idea.

    Thanks!

    #1319166
    Nabeel A
    Moderator

    Hi there,

    Thanks for writing in! Please add the following code in your Child Theme’s functions.php file:

    add_filter ('the_content', 'add_button_posts', 9999 );
    function add_button_posts ( $content ) {
    	$button = do_shortcode('<div style="text-align: right; margin: 5px 0;">[button type="flat" shape="pill" size="regular" href="#example" title="Example"][icon type="truck"]Pill Button[/button]</div>');
    	return is_singular('post') ? $button.$content.$button : $content;
    }

    Change the button shortcode attributes as per your need. Let us know how this gors!

    #1319599
    sandrayin
    Participant

    Hi Thanks! But can the top button be at the top of the post title? See attachment.

    #1319925
    Rue Nel
    Moderator

    Hello There,

    Thanks for updating in! To place the button on top of the title, please have the code updated and use this instead:

    add_filter ('the_content', 'add_button_posts', 9999 );
    function add_button_posts ( $content ) {
    	$button = do_shortcode('<div style="text-align: right; margin: 5px 0;">[button type="flat" shape="pill" size="regular" href="#example" title="Example"][icon type="truck"]Pill Button[/button]</div>');
    	return is_singular('post') ? $content.$button : $content;
    }
    
    add_action('x_before_view_renew__content_post-header', 'add_button_before_title');
    function add_button_before_title(){ 
    	if ( is_singular('post') ) {
    		echo do_shortcode('<div style="text-align: right; margin: 5px 0;">[button type="flat" shape="pill" size="regular" href="#example" title="Example"][icon type="truck"]Pill Button[/button]</div>');
    	}
    }

    Please let us know if this works out for you.

    #1320224
    sandrayin
    Participant

    Hi,

    Sorry, it didn’t work. Now the top button disappeared.

    #1320772
    Rad
    Moderator

    Hi there,

    I checked your other threads but I’m not sure which page you’re having this issue. Would you mind providing the exact URL? Maybe we could fix it by adding a javascript.

    Thanks!

    #1320804
    sandrayin
    Participant
    This reply has been marked as private.
    #1320912
    Rue Nel
    Moderator

    Hello There,

    Sorry if the code did not work out. There was a typo error in the code. I already updated it and now the button appears before the post title.

    http://prntscr.com/dsx83a

    Please check your site now.

    #1334677
    sandrayin
    Participant

    Thank you!

    #1334687
    Christopher
    Moderator

    You’re welcome.

  • <script> jQuery(function($){ $("#no-reply-1318849 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>