Block direct url enter

Preventing users from entering URLs manually in the address bar is not possible in WordPress, or from any site, for that matter. It can only be done via a browser plugin. However, redirecting users or displaying a 404 page for a certain URL is easy to do and there are several WordPress plugins for blocking … Read more

hide wp-content from urls

You don’t need a separate rule in your .htaccess. Add … define( ‘WP_CONTENT_DIR’, ‘YOUR_LOCAL_PATH’ ); define( ‘WP_CONTENT_URL’, ‘YOUR_PUBLIC_PATH’ ); … to your wp-config.php. Do not write into wp-settings.php. This file will be overwritten during the next update – never touch a core file.

How to properly print a 404 error without redirecton? (i.e. keeping the current URL)

You should be using a filter outside of your template for this: add_filter( ‘template_include’, ‘wpa62226_template_include’, 1, 1 ); function wpa62226_template_include( $template ){ if( is_page( ‘some-page’ ) ) : global $wp_query; $wp_query->set_404(); status_header( 404 ); $template = locate_template( ‘404.php’ ); endif; return $template; } Your code is executed before the template is loaded, so it becomes … Read more

Get Top parent url

You have to do it in a loop: $p = $post; while ( $p->post_parent ) { $p = get_post( $p->post_parent ); } $parent_page_link = get_permalink( $p->ID ); Another way is to use get_ancestors function: $ancestors = get_ancestors( $post->ID, ‘page’, ‘post_type’ ); $root = ( ! empty( $ancestors ) ) ? end($ancestors) : $post->ID; $parent_page_link = … Read more

hijacking home_url for root relative paths

You need to set the WP_HOME and WP_SITEURL in wp-config.php in a smarter way. Like this: <?php define(‘WP_HOME’, ‘http://’ . $_SERVER[‘HTTP_HOST’]); // add the next line if you have a subdirectory install define(‘WP_SITEURL’, WP_HOME . ‘/path/to/wordpress’); This will solve your your issues with site URLs as they will be set dynamically on based on whatever … Read more

previous_posts_link and next_posts_link, how to return the next/previous post’s title as the url

The functions you are using refer to the next or prev paginated set of posts, not a single post, hence the format they are in. Try using get_adjacent_post() instead. <?php $prev = get_adjacent_post(false, ”, true) $next = get_adjacent_post(false, ”, false) //use an if to check if anything was returned and if it has, display a … Read more

Remove trailing slash from previous_posts_link()

There’s two problems here: previous_posts_link() echoes the link, rather than returning it. previous_posts_link() returns the full HTML of the link, including <a href=””> etc. The problem with #1 is that for you to be able pass the result of a function to another function (such as rtrim()) as an argument, that function needs to return … Read more

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