Make attachment pages require a base url

Endpoints are for adding extra query vars to existing routes, I think you just want a vanilla rewrite rule here: function wpd_media_image_rewrite_rule() { add_rewrite_rule( ‘^image/([^/]*)/?’, ‘index.php?post_type=attachment&name=$matches[1]’, ‘top’ ); } add_action( ‘init’, ‘wpd_media_image_rewrite_rule’ ); You might want to loop over valid mime-types there and add a rule for each. You also need to flush rewrites for … Read more

Check what is at URI (post, archive, etc…)

Retrieve “type” of query from url: Previous suggestions As noted in the linked answer, there’s url_to_postid(). This will just get you the ID of the object at that endpoint. Long story short, this function will only return an ID and then run a new \WP_Query to get the post type object from the DB and … Read more

get_site_url is not returning anything?

The functions that start with “get_” return the value to what’s calling it. So you would do <a href=”https://wordpress.stackexchange.com/questions/11893/<?php echo get_site_url(); ?>”> instead to print out the URL.

permalink for category pages and posts

There’s currently no way in core to get the current archive / category / tag / custom taxonomy URL. I have a patch waiting for that to be added right here. For now though, you could just use the code in the last patch on that ticket: <?php /* Get the current archive link * … Read more

How to update media links in WordPress after migration?

As mentioned in the comments under your question, some data in the WordPress database is serialized and therefore not possible to change with a simple find and replace. You should read through the Moving WordPress section of the codex. Specifically the Changing Your Domain Name and URLs portion. I usually use a plugin or a … Read more

Add query string to plugin URL

When you don’t know if query string was started or not you can use add_query_arg which it knows how to deal with that and adds the “?” or “&” marks (which ever one is needed) to the query string. Update By popular demand I’m adding a few examples that are from the codex: Using get_permalink: … Read more

Remove the http protocol from images

The code you provided could cause issues with 3rd party URLs in hyperlinks not running https. You can fix this by including your home url, e.g: $content = str_replace( set_url_scheme( home_url(), ‘http’ ), set_url_scheme( home_url(), ‘relative’ ), $content); Next, you’re applying this when you’d like to display the content, which means you need to do … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)