Tag Info

Hot answers tagged

11

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


7

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


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


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

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

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


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

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

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

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

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

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


1

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


1

It depends on your image and stylesheet location. But this is the syntax: .theme-image { background-image: url('../images/header-img.jpg'); } The above code is for the structure wp-content - themes - your-theme - images - header-img.jpg - css - style.css You are making the browser come one directory before and search for images ...


1

For all my answers I'm assuming you both have the legal rights to use those images and are aware of any implications of duplicate content (SEO etc). That being said there are definitely ways. At what point would you like to scrape images? Regularly? If so look into WP_Cron and automate it. If you just want to scrape the image once you generate a new post, ...


1

As you want to change (use different) URL for featured image only, you can use pre_option_upload_url_path hook. // Setting the uploads directory URL function wpse_change_featured_img_url() { return 'http://www.example.com/media/uploads'; } add_filter( 'pre_option_upload_url_path', 'wpse_change_featured_img_url' ); This hook will not change URLs ...


1

Dave James Miller over at GitHub nailed this one for me. None of the work is from me, I'm just posting his code wrapped into a plguin since it works perfectly as advertised: <?php /** * Plugin Name: Set default category from url parameter * Plugin URI: https://gist.github.com/davejamesmiller/1966543 * Description: enables you to setup new post links ...


1

i think this can help you: use the below code in your theme's functions.php function redirect_homepage() { if( ! is_home() && ! is_front_page() ) return; wp_redirect( 'http://siteurl.com/news', 301 ); exit; } add_action( 'template_redirect', 'redirect_homepage' );


1

I pretty sure this filter lets you add an array of variables. I've not tested this: function add_custom_query_vars( $vars ){ $vars[] = "variable1"; $vars[] = "variable2"; $vars[] = "variable3"; //... etc return $vars; } add_filter( 'query_vars', 'add_custom_query_vars' ); Or another way of doing it would be to do this: function ...


1

The simplest and quickest solution would be to use the add_rewrite_endpoint function. <?php add_rewrite_endpoint( $name, $places ); ?> So in your case it would be something like this: add_rewrite_endpoint( 'user', EP_PERMALINK | EP_PAGES ); An user URL would look like this: http://www.example.com/my-page/user/john To access the variable: ...


1

Exist some WordPress function that retrieve the list of links (in my specific case only one) that are into a post? Check out the core wp_extract_urls() function: $urls = wp_extract_urls( $content ); that will extract urls from any given content. Example $content = 'Two test sites: <a href="http://foo.tld">Foo.tld</a> and ...


1

When adding an external link you need to include HTTP:// or HTTPS:// at the start of the URL to link to an external domain. Otherwise the link will be added onto the current domain.


1

You can set the rewrite slug when you register your post type: $args = array( 'rewrite' => array( 'slug' => 'media/lajmet' ) // other args... );


1

The WP function get_attached_media() should provide the info you need. If used in this way... $media = get_attached_media( 'image' ); ... the $media var should contain the wp_post objects for all attached images. Function documentation in the WP Codex: https://codex.wordpress.org/Function_Reference/get_attached_media


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



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