Support » Fixing WordPress » Edit link on post page

  • Resolved sharonvillines

    (@sharonvillines)


    The theme I’m using Zinnia doesn’t have a link on the posts page that admins can sue to edit the post.

    Is it possible to add this to a child theme?

    The Zinnia forum looks dead.

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Joy

    (@joyously)

    Yes, read about the function: https://developer.wordpress.org/reference/functions/edit_post_link/
    Be sure to scroll to the bottom to see the example code.

    Thread Starter sharonvillines

    (@sharonvillines)

    Thank you for responding. More questions as I’m clueless about php.

    Below is the code I pasted into the includes > modules.php . The choices were style.css, ace_functions.php, custom_widgets, modules.php, and widgets.php

    When I tried to save, got the error messages that I couldn’t redeclare the ‘edit_post_link’

    Did I put this in the wrong place?

    ——————

    function edit_post_link( $text = null, $before = ”, $after = ”, $id = 0, $class = ‘post-edit-link’ ) {
    $post = get_post( $id );
    if ( ! $post ) {
    return;
    }

    $url = get_edit_post_link( $post->ID );
    if ( ! $url ) {
    return;
    }

    if ( null === $text ) {
    $text = __( ‘Edit This’ );
    }

    $link = ‘‘ . $text . ‘‘;

    /**
    * Filters the post edit link anchor tag.
    *
    * @since 2.3.0
    *
    * @param string $link Anchor tag for the edit link.
    * @param int $post_id Post ID.
    * @param string $text Anchor text.
    */
    echo $before . apply_filters( ‘edit_post_link’, $link, $post->ID, $text ) . $after;
    }

    Joy

    (@joyously)

    The link I gave is the Code Reference. It shows you all the code that is in WordPress, and how to use it. The function, as the error message told you, is already in WordPress. You don’t put it again; you call it like in the examples at the bottom of that page. The call belongs in a template file where you want to see the link. That is usually in the theme’s single.php (which outputs the single post page) or in a template part that it uses such as content.php. Each theme is different, so you have to look for yourself to see how the theme is structured.
    The Template Hierarchy shows which template file is used for each type of page.

    Joy

    (@joyously)

    I just saw your other topic, and I want to suggest that some themes don’t put the edit link because it is available in the admin bar. So if you turn on the admin bar in your profile, you will see it on the front end of your site and you don’t need the edit link in your theme.

    Thread Starter sharonvillines

    (@sharonvillines)

    Perfect. I had never noticed that link because I always used the other one.

    Thank you!

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.