Tag Info

Hot answers tagged

10

You can get the value of front in the global $wp_rewrite: global $wp_rewrite; echo $wp_rewrite->front; // or echo home_url( $wp_rewrite->front ); Though that is probably of limited use, as the front base isn't necessarily an existing page, and may 404 in many cases. If you're using that value to prepend to other URLs, you're likely doing it wrong. ...


6

First of all I have to say that wp_get_referer() is not 100% reliable because it relies on $_SERVER['HTTP_REFERER'] that is not 100% reliable, from php.net docs: The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify ...


4

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 an ...


4

I was about to suggest something like the function bellow, but lets face it @Milo's answer is just a bit smarter, so just for completeness reason and because I already wrote it down. function wpse163163_site_url_with_fix_permalink_base() { return get_site_url() . '/' . preg_replace( '/\%([a-z0-9]+?)\%/i', ...


4

You can use wp-config.php to change the site url depending on where the site is accesed from, using $_SERVER['REMOTE_ADDR']. Mine has something like this: if ($_SERVER['REMOTE_ADDR'] == '127.0.0.1' || $_SERVER['REMOTE_ADDR'] == '::1') { // accesing site from my local server define('WP_SITEURL', 'http://localhost/mysite/'); define('WP_HOME', ...


3

Those are reserved keywords When you visit a WordPress blog you have: blogindexpage/?queryvariables=queryvalues So for a search request: example.com/?s=searchterm For a post/page of ID 12: example.com/?p=12 etc etc Pretty permalinks hides all this by using regular expressions to map nice looking URLs on to their equivalents. This doesn't prevent ...


3

You could make a list of paths to check... $page_paths = array( 'analysis/firstNamelastName', 'exercise/firstNamelastName' ); Then check if there's a page object for each of the page paths. foreach($page_paths as $page_path){ $page = get_page_by_path($page_path); if(!$page){ echo '<code>'.$page_path.'</code> Does not ...


2

You will need to use site_url($path_to_style_sheet, 'https') instead of bloginfo(). The home_url() method also supports https.


2

When you delete a post, it merely gets put into the "trash" and retains its slug. When you created the "new" contact page, the slug "contact" was already in use by the original contact post that is in the trash. Go into your posts on the dashboard and click on the "Trash" link near the top of the post listing. Once in the Trash area, permanently delete ...


2

This is a typical issue when moving WordPress sites. WordPress stores URLs - both main configuration URLs and resource URLs - in the database. These must be changed in the database when moving to a new domain or mail URL in localhost. Don't use simple SQL change queries in the database via adminer or phpmyadmin. WordPress and some themes store ...


2

Not completely sure I understand what you mean with that the parameters fall under a page job, but if you mean that different contents are loaded on the same page using javascript / ajax, you could use https://github.com/browserstate/history.js/ to generate the corresponding url for each state. Difficult to say more about how you could implement this without ...


2

In order to work permalinks properly, you have to enable 'mod_rewrite' module in your apache server. Other wise it could not run .htaccess file and that is why it shows 'Not found'. It will be working if the permalink is disabled or set to default, right?


2

There are four valid sizes built in to the WordPress core. the_post_thumbnail('thumbnail'); // Thumbnail (default 150px x 150px max) the_post_thumbnail('medium'); // Medium resolution (default 300px x 300px max) the_post_thumbnail('large'); // Large resolution (default 640px x 640px max) the_post_thumbnail('full'); // ...


2

The "cheapest" way to achieve this probably would be to simply add two pages: // Standard template http(s)://example.com/portfolio-xyz Then add another page with your second URl and use a custom page template where you query your single post using get_post() and display it however it pleases you: <?php /* Template Name: Alternate Portfolio PT template ...


2

The original intention of this question was to know where a single post was referred from and then according to that serve up the next and previous post according to the post referrer What I wanted to accomplish was for eaxample: A post is clicked on from a category, taxonomy, tag, search or author arhive page. These archives serves as referrers. Now, ...


2

Pro tip - don't custom query unless you need to (you don't). And never use the guid field. if ( is_singular() && $cats = get_the_category() ) $cat_id = $cats[0]->term_id; // Category ID for current post elseif ( is_category() ) $cat_id = get_queried_object_id(); // Category ID for current archive else $cat_id = 0; // No cats $posts = ...


2

I finally got it. First mistake was to process the same function twice. I've called it once after the function and one more time in ajax action. So when using the ajax call, the function got executed twice. In the example from the OP, this is not a problem at all, because it is simplified to do only one thing, but in my real code it does much more and can ...


2

See Changing The Site URL « WordPress Codex for recovery instructions on how to reset the URLs without database access, i.e. by editing either the wp-config.php file or the theme's functions.php file with FTP: 1) by adding lines to wp-config.php (which can be left in place): define('WP_HOME','http://example.com'); define('WP_SITEURL','http://example.com'); ...


2

If you check out the output() method in the includes/admin/class-wp-job-manager-setup.php file, namely this part: /** * Output addons page */ public function output() { $step = ! empty( $_GET['step'] ) ? absint( $_GET['step'] ) : 1; if ( 3 === $step && ! empty( $_POST ) ) { $create_pages = isset( ...


1

Do you have to use localhost for any particular reason? The easiest fix for this will be to make those functions work correctly by putting a real hostname or ip address into the site address field in WordPress settings. Look in Settings > General Settings.


1

You can not do that viw .htaccess because .htacces rules can not control how the permalinks are generated by WordPress. Instead, go to WordPress settings->permalink. Select custom structure and enter: blog/%category%/%postname%


1

Change Settings -> Permalinks to Post Name. Go to your page and edit the Permalink field below the title field.


1

Change the Settings -> Permalink to Custom Structure /%category%/%postname%/ Now while editing the post, check only the subcategory and now the parent category is nested within the URL automatically.


1

You can just look at url, load the file and exit. That can be done when WordPress loaded its environment, e.g. on 'init'. add_action('init', function() { $url_path = trim(parse_url(add_query_arg(array()), PHP_URL_PATH), '/'); if ( $url_path === 'retail' ) { // load the file if exists $load = locate_template('template-retail.php', true); ...


1

Make link like this <a href="http://example.com/?reaction=smk_remove_post&id=1226&_nonce=7be82cd4a0" data-id="1226" data-nonce="7be82cd4a0" class="smk-remove-post">Remove post</a> And jQuery $('.smk-remove-post').on( 'click', function( event ){ event.preventDefault(); var _this = $(this); var data = { 'action': ...


1

AJAX is not magical and when you request url X you will receive the same HTML for that url if you do it from the browser address bar, link or ajax. Therefor, if you want different response then the HTML you can not use the same url for the ajax request as in the link. Wordpress has a special "end point" to handle ajax request - admin-ajax.php and all ajax ...


1

This can be done by going to Settings -> Permalinks. On Permalinks page select Custom Structure: www.inspurate.com/blog/%postname%/


1

And the strange part: both codes echo the same string for $url!!! No, they don't. Look at the page source. esc_url() is encoding the & control character. You can't do that and expect the HTTP request to work correctly. Use esc_url_raw() instead. Note the description in the Codex concerning that function: The esc_url_raw() function is similar to ...


1

After checking phpinfo(), mod_rewrite wasn't enabled so I enabled it: http://linuxcommando.blogspot.fr/2014/03/how-to-enable-modrewrite-for-apache-web.html and it worked !


1

In WordPress, the footer scripts are enqueued using wp_enqueue_scripts into wp_footer(). So it is hard for you to find the direct scripts link in footer.php. To change the path you can go to PHPmyAdmin and edit the siteurl and home fields in options table of your database. You can include jQuery from CDN using the following code: // Register Script ...



Only top voted, non community-wiki answers of a minimum length are eligible