Exciting News! Flipper Code is now WePlugins! Same commitment to excellence, brand new identity.

How to use edit_bookmark_link filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
July 13, 2022
5 minutes read

edit_bookmark_link filter

Filters the bookmark edit link anchor tag.

To use the edit_bookmark_link filter, first you have to register it using add_filter. You can write this code into functions.php of your activated theme or in a custom WordPress Plugin.

WePlugins always prefer to create a custom WordPress Plugin while using hooks so nothing breaks when you update your WordPress Theme in the future.

In the below live example, we have defined a function modify_edit_bookmark_link_defaults which takes 2 parameters and we registered it using add_filter. The first parameter edit_bookmark_link is the name of the hook, the second parameter modify_edit_bookmark_link_defaults is the name of the function which needs to be called, the third parameter is the priority of calling the hook if the same hook is used multiple times, and the last parameter is the number of arguments (if any) to be passed in the registered function.

Sometimes, you have to remove a registered hook so you can use remove_filter to remove the edit_bookmark_link filter.

Parameters

    Below are the 2 parameters required to use this hook.

  • $link : (string) Anchor tag for the edit link.
  • $link_id : (int) Bookmark ID.

Live Example

apply_filters( 'edit_bookmark_link', string $link, int $link_id )

Below is an example of how you can use this hook.

  function modify_edit_bookmark_link_defaults($link, $link_id) { 
      // Update the $link variable according to your website requirements and return this variable. You can modify the $link variable conditionally too if you want.
      return $link; 
  }
  // add the filter
  add_filter( "edit_bookmark_link", "modify_edit_bookmark_link_defaults", 10, 2 );
  

To remove a hook callback, use the example below.

remove_filter( "edit_bookmark_link", "modify_edit_bookmark_link_defaults", 10, 2 );

Please make sure to provide the same callback function name, priority, and number of arguments while removing the hook callback.

Example 1: Customizing the Edit Bookmark Link

In this example, we will customize the edit bookmark link to include additional classes for styling.

  function weplugins_customize_edit_bookmark_link($link, $link_id) {
      // Add a custom class to the edit link
      $link = str_replace('class="', 'class="custom-class ', $link);
      return $link;
  }
  add_filter("edit_bookmark_link", "weplugins_customize_edit_bookmark_link", 10, 2);
  

Example 2: Adding a Query Parameter to Edit Bookmark Link

This example demonstrates how to add a query parameter to the edit bookmark link.

  function weplugins_add_query_to_edit_link($link, $link_id) {
      // Add a query parameter to the edit link
      $link = add_query_arg('source', 'custom', $link);
      return $link;
  }
  add_filter("edit_bookmark_link", "weplugins_add_query_to_edit_link", 10, 2);
  

Example 3: Changing the Anchor Text of Edit Bookmark Link

In this example, we will change the anchor text of the edit bookmark link.

  function weplugins_change_anchor_text($link, $link_id) {
      // Change the anchor text of the edit link
      $link = str_replace('Edit', 'Modify', $link);
      return $link;
  }
  add_filter("edit_bookmark_link", "weplugins_change_anchor_text", 10, 2);
  

Access Premium WordPress Plugins

Contact Us

If you need any customization or have any questions, feel free to contact us.

Sandeep Kumar Mishra

Sandeep Kumar Mishra

Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.

Explore the latest in WordPress

Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.