Hot answers tagged

16

Good news for WordPress versions 4.2+ Since version 4.2 the handy get_avatar_url() function, introduced as a feature request in ticket #21195 few years ago, now ships with the core: /** * Retrieve the avatar URL. * * @since 4.2.0 * * @param mixed $id_or_email The Gravatar to retrieve a URL for. Accepts a user_id, gravatar md5 hash, * ...


7

The following code will work, but you just have to keep in mind that conflicts can happen easily if the slug for your custom post type is the same as a page or post's slug... First, we will remove the slug from the permalink: function na_remove_slug( $post_link, $post, $leavename ) { if ( 'events' != $post->post_type || 'publish' != ...


7

You can use template_include, but before you hook to this filter you must do the following steps: Create page template. e.g: page-target.php <?php /** * Template Name: Page Target */ ... Manually query the contents of target-page on page-target.php template, because the global $post will be referencing to your some-prefix-* page. (Optional): Edit ...


5

I want ot give you an "alternate" approach. I'm pretty sure you're not going to follow this, but I thinks is interesting to read. OOP "routing" approach In WordPress, "pretty" urls are mathed to "ugly" urls. But most web frameworks (not only PHP) uses the concept of "routing": to match an url to an "action" (or a controller). I want to give you an idea ...


5

I am not sure if this is the best solution or not, but it works: function movie_review_permalink( $url, $post, $leavename ) { $category = get_the_category($post->ID); if ( !empty($category) && $category[0]->slug == "test" ) { //change 'test' to your category slug $date=date_create($post->post_date); $my_date = ...


5

I tried to figure this out not long ago and the short answer from what I know is no. Not from within the rewrite argument at least. The long explanation becomes apparent if you look at the actual code of register_post_type in wp-includes/post.php line 1454: add_permastruct( $post_type, "{$args->rewrite['slug']}/%$post_type%", $permastruct_args ); You ...


5

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', ...


4

Note that search engines might not like multiple paths to the same content! Here I assume you want e.g.: example.tld/some/path/to/painting-orange example.tld/painting-blue example.tld/painting-red example.tld/painting-yellow to behave like it was this page: example.tld/paintings but not so for paths like: ...


4

yes, but: it might be hard if drupal mixes several types of content under the /node/ parent. Those are not very SEO or even human freindly URLs so you might actually want to change them and just have a redirect from the old one to the new one.


3

Yes it is possible, but there isn't much point in that. The crudest way is to use a filter on the result of getting the 'rewrite_rules' option, and manipulating it by adding the entries you require directly to the array, and then you might need to filter those rules out when the option is updated. The thing is that it is most likely a waste of time as as in ...


3

In response to my previous answer: you could of course set the rewrite parameter to false when registering a new post type and handle the rewrite rules yourself like so <?php function wpsx203951_custom_init() { $post_type = 'event'; $args = (object) array( 'public' => true, 'label' => 'Events', 'rewrite' ...


2

It was woocommerce, it has a setting "geolocalize users with cache support" which adds this parameter to every single url and link. I noticed that the hash appended was the same in every browser on my computer, so I realized it wasn't a "session" hash, but an IP address hash.


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

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


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

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

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


2

Well, AUTH_KEY and it´s brothers where introduced in WordPress 2.6 to improve safety for logged in users. They are used to encrypt and validate the information in your backend login cookie. While revealing the AUTH_KEY alone might not be a real security issue, you should nevertheless not output/use this anywhere to give less surface for attacks. ...


1

It looks like you use the Jetpack Plugin with Photon function (Wordpress.com photo CDN) https://jetpack.me/support/photon/ https://developer.wordpress.com/docs/photon/ You have to deactivate the Photon option in the Jetpack plugin settings.


1

Try the fourth input parameter (available in 4.2+): @param string $return Optional. Accepts 'html' (image tag html) or 'src' (URL). Default 'html'. So change your code snippet to: $new_image_url = media_sideload_image($new_url, $post_ID, $title, $src = 'src' ); to get the src instead of the default html. Note that the output might also be an ...


1

You can make the skype: as an acceptable protocol by adding the following code in the functions.php file of your child theme or develop a small plugin and add it in that plugin file. /** * Allows users to save skype protocol skype: in menu URL */ function vvd_allow_skype_protocol( $protocols ){ $protocols[] = 'skype'; return $protocols; } ...


1

You can read data on your server with file_get_contents(). If you want to make sure the file exists and is readable then use is_readable(). You don't really need to use trailingslashit() in this case because you're constructing the URI yourself. // path to file under current theme $json_file = get_template_directory() . ...


1

Kind of depends on where you are in the WordPress environment. Plugins If you're in a plugin, you can use plugins_url. <?php $url = plugins_url('css/admin.css', __FILE__); The above will give you the path relative to the file passed into the second argument. So if you're in the main plugin file you might get something like ...


1

The first form: <form method="post" action="some-url.php"> <input type="email" placeholder="Email address" value="" name="email"> <input type="submit" value="Submit" name="email-submit"> </form> Then in some-url.php: if( isset($_POST['email'] ) $email = $_POST['email'] The post method would be preferred here since it ...


1

If the front page is set to display posts then the query for those posts will run regardless of wether your theme shows these posts or not. That's why you're getting pagination with no posts. You can test this by temporarily removing your themes front-page.php (or whatever it is). You should see all your posts with correct pagination. You have 2 options to ...


1

You are on the right track. Point your add-on domains to Wordpress root Create Wordpress landing pages Point to landing page using add-on domain Rel=canonical will prevent duplicate indexing penalty All landing page links will automatically point to canonical domain Naturally you will do all your editing from the canonical domain If you run into trouble ...


1

The best way to fix this is to install PHPmyAdmin and then navigate to the wp-options table and change the site-address row. To install PHPmyAdmin, click on "Browse Marketplace" and search for PHPmyAdmin.


1

@Pat Gilmour is on the right track. The source to handle this is here. First thing you want to do is open the wp-config.phpfile in your SFTP (secure FTP). Add these two lines to your wp-config.php, where "example.com" is the correct location of your site. define('WP_HOME','http://example.com'); define('WP_SITEURL','http://example.com'); Read that ...


1

You would want to filter the category link to add the custom variable to the category link. You can make use of the get_term_link filter to filter the category link address Here is a very basic idea: Suppose that we, taken from OP, that you need to add the custom variable only to terms belonging to the build in taxonomy category, and only when we are on a ...


1

You need to build a proper meta_query. Your code will only work when you have one meta_key set, if you have more than 1, everything will be haywire. Also note, you should never ever use any unsanitized, non validated values from a $_GET variable (and for that matter any value coming from anywhere). It is extremely easy to inject malicious code into your ...



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