In the blog I have created, there is an edit link at the bottom of each post when you look at the live site whilst logged in as admin.
Website client looking for a way to have that edit link on the ‘blogroll’ homepage so that it appears underneath each blog post excerpt.
I’ve looked all over google for an answer but can’t find anything. I don’t even think it’s possible given what I understand about WordPress codex conditional logic.
Can someone please let me know if it is possible or not and how to approach this problem?
==Update==
Ok with Tim’s guidance, I located the content.php where the excerpt logic was being produced for the blog roll. Inserted Tim’s proposed code like so:
<?php if ( true == generate_show_excerpt() ) : ?>
<div class="entry-summary" itemprop="text">
<?php the_excerpt(); ?>
<?php
if(is_user_logged_in() && current_user_can("edit_post", get_the_ID())){
edit_post_link("Edit this post");
}
?>
</div><!-- .entry-summary -->
<?php else : ?>
<div class="entry-content" itemprop="text">
<?php the_content(); ?>
<?php
wp_link_pages( array(
'before' => '<div class="page-links">' . __( 'Pages:', 'generate' ),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->
<?php endif; ?>
Just had to make sure it was wrapped in a PHP function call ( i.e. ).
Seems to work the treat.
It most definitely is possible! 🙂
In your theme, you’ll have most likely a
home.php
,archive.php
orindex.php
file that is running through a loop of your posts. In that file, there’ll be code that looks like this:You’ll need to locate directly where to put this, but somewhere in that while loop will be your excerpts (most likely looking like
get_the_excerpt();
or similar). After that, you can place theedit_post_link()
function.Wrapped in a condition to check that a user is logged in and has permission to view the post, this will print out the ‘edit post’ link you are looking for:
Where exactly you place this depends on your theme and how it is constructed, but with a bit of looking around hopefully you will be able to locate it. Feel free to edit your question and place in the portion of code you are trying to edit if its not working for you.
If you’re using a main theme with a child theme, then you should look for the relevant portion of code in your main theme, and copy the file into your child theme to make changes.
Hello this is a simple task
Put this code inside the if admin login condition with in the loop..
In my particular WordPress installation using GeneratePress theme, I put this php code into my child theme functions.php file to solve the issue:
Just need to reposition where the edit button appears as right now it’s next to the author and I want it to be under the excerpt text.