- This topic has 11 replies, 2 voices, and was last updated 3 years, 2 months ago by Elvin.
-
AuthorPosts
-
November 14, 2019 at 11:29 am #1063305Jim
I’m guessing this might require editing a child theme template, but not quite sure which one or exactly how…
How can I add and style an “Edit” link next to each post on the Blog Archives pages? This needs to only be visible to logged in Admin users. Clicking the link would open the post editor for that specific post, or page.
Once logged in, the “Edit Post” link in the Admin Bar is fine for editing that post. Our previous theme, however, displayed an “Edit” link under the title of each post on the Blog Archives, tag/category listings, or Search Results page.
Thanks!
November 14, 2019 at 6:35 pm #1063533TomLead DeveloperLead DeveloperHi there,
Try this:
1. Add a Hook Element: https://docs.generatepress.com/article/hooks-element-overview/
2. Give it this content:<?php edit_post_link( __( 'edit', 'textdomain' ), '<p>', '</p>' ); ?>
3. Check the “Execute PHP” option.
4. In the Display Rules, choose your archives/search results and make it so it only appears to logged in users.
Hope this helps π
November 15, 2019 at 10:37 am #1064287JimThank you!
We have not yet activated the Elements module. Does that have any additional impact on PageSpeed performance? For example, are additional resources loaded on all pages, even if no custom elements are being called?
November 15, 2019 at 10:43 am #1064293LeoStaffCustomer SupportShould only have minimal impact.
You can do a quick speed test before and after adding the code.
November 15, 2019 at 10:54 am #1064306Jim“minimal” is relative… π
Thanks again.
November 15, 2019 at 10:55 am #1064307LeoStaffCustomer SupportNo problem π
January 26, 2021 at 9:31 pm #1635086BudiHello,
Below code works on single post, but not on blog archive
add_action( ‘generate_after_content’,’generate_add_edit_link’ );
function generate_add_edit_link()
{
if ( ! is_singular() )
return;edit_post_link( __( ‘Edit’, ‘generatepress’ ), ‘<footer class=”entry-meta”><span class=”edit-link”>’, ‘</span></footer>’ );
}If I want to add ‘edit link’ on blog archive, what code should I add without using hook ?
Thanks.
January 26, 2021 at 10:18 pm #1635103ElvinStaffCustomer SupportHi,
You can follow Tom’s recommendation.
Use a Hook Element and place this on the code area:
<?php edit_post_link( __( 'Edit', 'generatepress' ), '<footer class="entry-meta"><span class="edit-link">', '</span></footer>' ); ?>
You then set the hook to
generate_after_content
and set the display rule to “posts – all posts”, “all archives”, “blog” and “search results. Also make sure that “Execute PHP” is checked.Hook and Code
https://share.getcloudapp.com/Jru1AAzBDisplay rules
https://share.getcloudapp.com/NQuJOOzgJanuary 27, 2021 at 12:03 am #1635145BudiIs it possible not to use hook element ?
Thanks.January 27, 2021 at 2:17 am #1635254ElvinStaffCustomer SupportYou can try this out.
add_action( 'generate_after_content','generate_add_edit_link' ); function generate_add_edit_link() { if(is_user_logged_in() && current_user_can("edit_post", get_the_ID()) && !is_page() ){ edit_post_link( __( 'Edit', 'generatepress' ), '<footer class="entry-meta"><span class="edit-link">', '</span></footer>' ); } else { return; } }
The edit link is visible to logged in users with edit post permission.
I’ve also added
&& !is_page()
within the condition so it doesn’t appear on static pages (but will appear on blog, archive, search and single posts).January 27, 2021 at 7:35 am #1635773BudiThanks, the code is running well.
January 27, 2021 at 7:53 pm #1636374ElvinStaffCustomer SupportNice one. Glad you got it sorted. π
-
AuthorPosts
- You must be logged in to reply to this topic.