How can I get the page url slug when ‘post_name’ returns an id?

Try this : $menu = get_term( $locations[$theme_location], ‘nav_menu’ ); $menu_items = wp_get_nav_menu_items($menu->term_id); foreach( $menu_items as $menu_item ) { $link = $menu_item->url; $title = $menu_item->title; $slug = basename($menu_item->url); } Pass the whole permalink to the basename function, which will automatically process the URL and give us only the slug.

WP Nav menu append to url

I found the solution modifying the behaviour of wp_nav_menu with the wp_get_nav_menu_items-filter. Here’s a somewhat complete example: class ModifyLinkFilter { protected $_prio = 10; protected $_args; public function __construct($addargs = array(), $prio = 10) { $this->_args = $addargs; $this->_prio = $prio; if(!empty($addargs)) { $this->register(); } } public function register() { add_filter(‘wp_get_nav_menu_items’, array($this, ‘on_nav_items’), $this->_prio, 3); … Read more

How to redirect visitor to a custom URL using PHP code in functions.php

First, it is hard to believe that wp_redirect isn’t working, below some (example) code how to use it: function wpse101952_redirect() { global $post; if( /*SOME CONDITIONAL LOGIC*/ ) { //examples: is_home() or is_single() or is_user_logged_in() or isset($_SESSION[‘some_var’]) wp_redirect( /*SOME SPECIFIC URL*/ ); exit(); } } add_action( ‘template_redirect’, ‘wpse101952_redirect’ ); Second, there would be the question … Read more

A way to change image urls in post to cdn image url?

You can parse via regex for images in the_content; but is always load and slowly. Maybe you change the url of images, after post_save in database or change the current posts inside the database and create an custom CDN. Its the fast way and all caching plugins has the break, that she must parse the … Read more

“Reversable” and “Re-useable” Subcategories (or other taxonomic structure)

The only possible way I can think to achieve this would be through getting neck deep in rewrite rules. You would have to flip your actual category structure around so that ‘exotic’ is the parent category, with two subcategories, ‘design’ and ‘travel’. Obviously you would put any posts you wanted in /design/exotic, into /exotic/design, same … Read more

Change code to display image attachment page

As pointed in the other answer, you should not have prettyPhoto part The link should be changed to utilize the function get_attachment_link Basically change this line in your code $link = ‘<a href=”‘.get_attachment_link($id).'”>’.wp_get_attachment_image($id, $size, false).'</a>’;