remove links from images using functions.php

add_filter( ‘the_content’, ‘attachment_image_link_remove_filter’ ); function attachment_image_link_remove_filter( $content ) { $content = preg_replace( array(‘{<a(.*?)(wp-att|wp-content\/uploads)[^>]*><img}’, ‘{ wp-image-[0-9]*” /></a>}’), array(‘<img’,'” />’), $content ); return $content; } The regex could be simpler and unfortunately this also deprives you of the unique wp-image-xxx (where xxx is the attachment ID) class of the <img> tag, but it’s the safest one I … Read more

Get the prev / next page links only (not title, etc)

Short answer: get_previous_posts_page_link is the function you want: <?php if($url = get_previous_posts_page_link()): ?> do stuff with $url <?php endif; ?> Longer answer: follow the code. previous_posts_link calls get_previous_posts_link. <?php /** * Display the previous posts page link. * * @since 0.71 * @uses get_previous_posts_link() * * @param string $label Optional. Previous page link text. */ … Read more

Add custom menu item using wp_nav_menu_items filter

I’ve created these two functions you may use to add custom items to a given menu item present in your menu (page, post, link…). In your case, you can add these function to your functions.php and call them like this: $menu_name=”Your Menu Name”; $name_of_menu_item_to_append_to = ‘My Account’; $id_of_menu_item_to_append_to = get_wp_object_id( $name_of_menu_item_to_append_to, ‘nav_menu_item’ ); $new_submenu_item = … Read more

How to print translation supported text with HTML URL

Since esc_html_e will escape HTML link (hence will show the HTML anchor as plain text), you’ll need to segment the text and escape the non-HTML part with esc_html_e or esc_html__, and print the HTML LINK part without HTML escaping. Method-1 (just for your understanding): You may do it in parts, like this: esc_html_e( ‘Dear Guest, … Read more

On the WordPress Admin section how do I link to submenu pages created for a plugin?

admin_url() gets you the correct administration page URL (and network_admin_url() to get a network administration page URL) Optionally, you can use add_query_arg() to append arguments to an URL, using an associative array: $page=”edit_record_page”; $rec_id = 1; $record_url = add_query_arg(compact(‘page’, ‘rec_id’), admin_url(‘admin.php’));

Add CSS Class to Link in TinyMCE editor

One option is to add a class to the Styleselect menu in MCE. Adapted from the “TinyMCE Custom Styles” Codex page you first need to add the style select to the editor: // Callback function to insert ‘styleselect’ into the $buttons array function my_mce_buttons_2( $buttons ) { array_unshift( $buttons, ‘styleselect’ ); return $buttons; } // … Read more

How to use wpLink without editor?

There is not ethical way of doing this. But still there is a way to do this. WordPress wrote wpLink script keeping in mind that editor is there but still WordPress handle when editor is not there (Good Thing) Consider this example and assume that we are using it on front-end in footer. First enqueue … Read more