All Wordpress Themes

How to add custom link to the right sidebar on the page

Before editing or replacing files, strongly recommended to create backup of your files!
Need to edit and add a lot of code. You can download edited files here. But if you have already edited any of these files, you should change code manually.

1. Open file page.php (it lays in directory \wp-content\themes\getphoto\includes\acf\page-templates\).
Add next code to the bottom:

if(function_exists("register_field_group"))
{
register_field_group(array (
'id' => 'acf_sidebar-link',
'title' => 'Sidebar Link',
'fields' => array (
array (
'key' => 'field_527aa5136afa6_link',
'label' => 'Add link to sidebar?',
'name' => 'add_sidebar_link',
'type' => 'true_false',
'message' => '',
'default_value' => 0,
),
array(
'key' => 'field_535e7d89bf8d4_link_label',
'label' => '',
'name' => 'sidebar_link_label',
'type' => 'text',
'instructions' => 'Write name of sidebar button.',
'default_value' => 'Link',
'placeholder' => '',
'conditional_logic' => array (
'status' => 1,
'rules' => array (
array (
'field' => 'field_527aa5136afa6_link',
'operator' => '==',
'value' => '1',
),
),
'allorany' => 'all',
),
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
array(
'key' => 'field_535e7d89bf8d4_link',
'label' => '',
'name' => 'sidebar_link',
'type' => 'text',
'instructions' => 'Write here link as http://google.com or mypage (will work as http://mysite.com/mypage).',
'default_value' => 'http://',
'placeholder' => '',
'conditional_logic' => array (
'status' => 1,
'rules' => array (
array (
'field' => 'field_527aa5136afa6_link',
'operator' => '==',
'value' => '1',
),
),
'allorany' => 'all',
),
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
array(
'key' => 'field_535e7d89bf8d4_link_ico',
'label' => '',
'name' => 'sidebar_link_ico',
'type' => 'text',
'instructions' => 'Write here class for icon. Defualt is "ggticon-Broke-Link2"',
'default_value' => 'ggticon-Broke-Link2',
'placeholder' => '',
'conditional_logic' => array (
'status' => 1,
'rules' => array (
array (
'field' => 'field_527aa5136afa6_link',
'operator' => '==',
'value' => '1',
),
),
'allorany' => 'all',
),
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
array(
'key' => 'field_535e7d89bf8d4_link_target',
'label' => '',
'name' => 'sidebar_link_target',
'type' => 'true_false',
'instructions' => 'Open link on new page?',
'default_value' => 0,
'placeholder' => '',
'conditional_logic' => array (
'status' => 1,
'rules' => array (
array (
'field' => 'field_527aa5136afa6_link',
'operator' => '==',
'value' => '1',
),
),
'allorany' => 'all',
),
),
),
'location' => array (
array (
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'page',
'order_no' => 20,
'group_no' => 0,
),
),
),
'options' => array (
'position' => 'normal',
'layout' => 'default',
'hide_on_screen' => array (
),
),
'menu_order' => 2,
));
}

2. Open file helpers.php (it lays in directory \wp-content\themes\getphoto\includes\)
2.1 Find code:


case "Mute":
$real_name = theme_option("bar_mute") ? theme_option("bar_mute") : $name;
break;

and add this code below:

case "Link":
$real_name = ggt_get_field("sidebar_link_label") ? ggt_get_field("sidebar_link_label") : $name;
break;

2.2 Find code:


if (theme_option("about_switch")):
ggt_appbar_item("bar-about", "ggticon-Information", ggt_get_bar_name("About"), "about");
endif;

and add this code below:


if (ggt_get_field("sidebar_link_label")):
(ggt_get_field("sidebar_link_ico")) ? $link_ico = ggt_get_field("sidebar_link_ico") : $link_ico = "ggticon-Broke-Link2";
ggt_appbar_item("bar-link", $link_ico, ggt_get_bar_name("Link"), "link");
endif;

2.3  Find code:

<div class="bar-item-label"> <div class="inside"><?php echo esc_html($label); ?></div> </div>

and replace it with new one:

<div class="bar-item-label"> 
<?php if($content_type=="link"){ ?> 
<a class="inside" 
<?php if (ggt_get_field("sidebar_link")){echo 'href="'.ggt_get_field("sidebar_link").'" ';}?> 
<?php if (ggt_get_field("sidebar_link_target")){echo 'target="_blank" ';}?> 
> 
<?php echo esc_html($label); ?> 
</a> 
<?php }else{?> 
<div class="inside">
<?php echo esc_html($label); ?></div> <?php }?> 
</div>

3. Open file main.js (it lays in directory \wp-content\themes\getphoto\js\),
find this code:


var $bar = $("#main-app-bar"),
$items = $bar.find(".app-bar-item");

and replace it with new one:

var $bar = $("#main-app-bar"),
$items = $bar.find(".app-bar-item").not("#bar-link");

Before editing or replacing files, we strongly recommend to make backup of your files!

Now you can add own custom link to page you want.

Screenshot_15