This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
get_sample_permalink_html filter
Filters the sample permalink HTML markup.
To use the get_sample_permalink_html filter, you first need to register it using add_filter. You can include this code in the functions.php file of your activated theme or in a custom WordPress Plugin.
We at 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 live example below, we have defined a function weplugins_modify_get_sample_permalink_html_defaults which takes 5 parameters and is registered using add_filter. The first parameter get_sample_permalink_html is the name of the hook, the second parameter weplugins_modify_get_sample_permalink_html_defaults is the name of the function 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 to the registered function.
Sometimes, you might need to remove a registered hook, so you can use remove_filter to remove the get_sample_permalink_html filter.
Parameters
Below are the 5 parameters required to use this hook:
- $return : (string) Sample permalink HTML markup.
- $post_id : (int) Post ID.
- $new_title : (string) New sample permalink title.
- $new_slug : (string) New sample permalink slug.
- $post : (WP_Post) Post object.
Live Example 1
Below is an example of how you can use this hook.
function weplugins_modify_get_sample_permalink_html_defaults($return, $post_id, $new_title, $new_slug, $post) { // Update the $return variable according to your website requirements and return this variable. You can modify the $return variable conditionally too if you want. return $return; } // Add the filter add_filter("get_sample_permalink_html", "weplugins_modify_get_sample_permalink_html_defaults", 10, 5);
Live Example 2
To remove a hook callback, use the example below.
remove_filter("get_sample_permalink_html", "weplugins_modify_get_sample_permalink_html_defaults", 10, 5);
Ensure you provide the same callback function name, priority, and number of arguments while removing the hook callback.
Live Example 3
Here is another example of modifying the sample permalink HTML:
function weplugins_custom_permalink_html($return, $post_id, $new_title, $new_slug, $post) { // Custom logic to modify the permalink HTML $return = '<div class="custom-permalink">' . $return . '</div>'; return $return; } // Add the filter add_filter("get_sample_permalink_html", "weplugins_custom_permalink_html", 15, 5);
Contact Us
If you need any customization or have trouble using this hook, please contact us.
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.