Community Forums › Forums › Archived Forums › Design Tips and Tricks › How to add 'Back to Blog link' from a website page?
Tagged: Backtoblog link, linking pages
- This topic has 9 replies, 2 voices, and was last updated 9 years, 8 months ago by varshasalvi.
-
AuthorPosts
-
August 6, 2014 at 8:35 pm #117500varshasalviMember
Hello ,
I am trying to add a link which says "Back to Blog" on the Art-Gallery page of my site.
Within the art-gallery which is using a jetpack plugin to display slideshow of images , I have managed to put a 'Back To Art Gallery' link on the slideshow page to go back to the main page. I did this by adding
BACK TO PORTFOLIO, a simple codeline on each gallery page that I created.However I am not able to figure out how to add a 'back to blog' link from the main art-gallery page. Is it as simple as adding the above code ? if yes where should I place it?
my site is : designforsoul.com
http://designforsoul.com
Thanks!August 6, 2014 at 8:43 pm #117501Brad DaltonParticipantHello Varsha
Firstly, you need to decide which hook position you want the link to display.
genesis_after_loop maybe a good hook
Then you can hook it in using a custom function and conditional tag
In your case, the conditional tag will be something like
if ( is_post_type_archive('art-gallery') )
August 7, 2014 at 1:09 pm #117621varshasalviMemberHi Brad,
I am using this code :
add_action( 'genesis_after_loop', 'wpsites_hook_back-to-blog', 25 );
function wpsites_hook_back-to-blog() {
if ( is_post_type_archive('art-gallery') ) {
echo'<div class="custom-back-to-blog">';
echo'BACK TO BLOG';
echo'</div>';
}
}
But it is giving me an error! I got this snippet from the link you provided above and changed the genesis-before-loop to after , changed the conditional tag and button class to back-to-blog class i created in CSS.Could you tell me where am I going wrong?
August 7, 2014 at 7:54 pm #117685Brad DaltonParticipantPlease embed the code correctly using Github Gists
Whats the error message and where did you paste the code?
August 7, 2014 at 8:01 pm #117688Brad DaltonParticipantHere's what the code does:
You can change the text and style or remove the button so its simply a text link by removing the CSS
August 7, 2014 at 8:56 pm #117697varshasalviMemberI pasted the code in the functions.php folder of my current child theme which is 'Beautiful Pro'.
I did use Notepad++ to copy the code first
August 7, 2014 at 11:17 pm #117708Brad DaltonParticipantWhich code snippet?
There's 2
The first one only works in the template file and the 2nd only works in the functions file.
You can just copy and paste code into any file and expect it to work and not cause problems.
Also, the HTML needs to go in a text widget and won't work in the functions file.
Whats the error message?
August 8, 2014 at 2:18 pm #117814varshasalviMemberI got it it to work . I do not not have a knowledge about php but I am learning as i go . I made a mistake in the loop
add_action( ‘genesis_after_loop’, ‘wpsites_hook_button’, 25 );
function wpsites_hook_button()
I changed button with back to blog.However, now its a button on the page and if I change the CSS to make it look like a link the css of other buttons on the page also changes.
Is there a way to avoid that ? I am thinking I will have to create like another custom(button/link or something)
Also, if I have to do the same thing for portfolio page , i have to just replace the conditional tag toif ( is_post_type_archive('portfolio') )
right?
August 8, 2014 at 9:54 pm #117863Brad DaltonParticipantJust create a HTML link in a new post draft and replace that with the code for the button like this:
echo' Your HTML link goes here ';
Do the same for the portfolio CPT yes
August 9, 2014 at 12:53 pm #117955varshasalviMemberPerfect ! Thanks Brad.
I am facing one more issue though:(
I am using the same code for Portfolio CPT and its not working
add_action( 'genesis_after_loop', 'wpsites_hook_button', 25 );
function wpsites_hook_button() {
if ( is_post_type_archive('portfolio') ) {
echo'<div class="back-to-blog">';
echo'BACK TO BLOG';
echo'</div>';
}
}The error is that the page just goes blank when I update the functions.php file. Have no idea why this is happening.
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.