Media/attachment urls don’t redirect with fake URL structure

Milo got me on the right track. If anyone else happens to have this issue the code I used is: /** * Redirect broken attachment links to 404 */ function ww_404_broken_links(){ global $wp_query; if(is_attachment()){ $attachment_path = get_attached_file( get_the_ID() ); //If the file doesn’t exist on the server show 404 if(!file_exists($attachment_path)){ $wp_query->set_404(); status_header( 404 ); get_template_part( … Read more

Permalink for PDF of article

Using add_rewrite_endpoint <?php if ( ! class_exists( ‘PDFRewriteEndpoint’ ) ): class PDFRewriteEndpoint { /** * Add actions and filters in constructor. */ public function __construct() { add_action( ‘parse_request’, array ( $this, ‘sniff_requests’ ), 0 ); add_action( ‘init’, array ( $this, ‘add_endpoint’ ), 0 ); } /** * Add rewrite rules. */ public function add_endpoint() { … Read more

Echo title with permalink

This is the problem: $link = the_permalink(); Replace it with: $link = get_permalink(); Notice that the WordPress the_* functions will echo the output, but get_* will return it. But of course there are exceptions to this rule 😉 So you don’t need this: echo the_title(); Just use this instead: the_title(); or the usage example given … Read more

How Do I get the author’s page id?

It sounds like you need get_author_posts_url() which “Gets the URL of the author page for the author with a given ID.” If you have set the custom permalink correctly it should work. If you really are looking for actual page IDs, there is no page ID for an author archive page. Those pages are dynamically … Read more

Permalink for specific page name

In your .htaccess you should be able to do something like what is shown by Chris Coyier on CSS Tricks. Link to example by Chris Coyier: https://css-tricks.com/snippets/htaccess/subdirectories-redirect-query-string/ Since you don’t have .php in your URL, WordPress has most likely already created RewriteEngine rules for you to not need .php. But the result should still work … Read more

Custom post type clean shortlink

Yes this is correct. You can choose custom permalink the way you want. But it is limited to these official tags only. And %post_id% is one of those tags so you can use it. Just a note here you need to end the custom structure with post ID or name as codex says Make sure … Read more

Add a filter to get_comments_link()

Modifications of the core code are not recommended. Note that the core get_comments_link() function considers two cases of $hash: $hash = get_comments_number( $post_id ) ? ‘#comments’ : ‘#respond’; Also note the second input argument is $post_id. Here’s your modified example: add_filter( ‘get_comments_link’, function( $link, $post_id ) { $hash = get_comments_number( $post_id ) ? ‘#mycomments’ : … Read more

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