How do i reference the theme path in pages for images?

Use get_template_directory_uri() print get_template_directory_uri() . ‘/image.jpg’; In child themes use get_stylesheet_directory_uri() if you have replaced the image. In a shortcode this would look like this: <?php /* Plugin Name: Theme URI Shortcode */ add_shortcode(‘theme_uri’, ‘wpse_66026_theme_uri_shortcode’ ); function wpse_66026_theme_uri_shortcode( $attrs = array (), $content=”” ) { $theme_uri = is_child_theme() ? get_stylesheet_directory_uri() : get_template_directory_uri(); return trailingslashit( $theme_uri … Read more

Set template based on query in URL

There are a number of template filters available to override template selection. For a single post you can use the single_template filter: function wpa_single_template( $template ) { if( isset( $_GET[‘template’] ) ) { $template = locate_template( $_GET[‘template’] . ‘.php’, false ); } return $template; } add_filter( ‘single_template’, ‘wpa_single_template’ );

Is revealing just the AUTH_KEY a security issue?

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 … Read more

Concatenate site_url and string doesn’t work

Without knowing exactly what you are trying to do, it seems you want to append query variables to the URL. WordPress has methods for handling that properly, without manual string concatenation. Look at the documentation for add_query_arg() for details: https://developer.wordpress.org/reference/functions/add_query_arg/ You can rebuild the URL and append query variables to the URL query by using … Read more

How to get “extended” path info from URL in a plugin

In reply to “Update 1“: The code worked fine for me. So, I’m still getting a 404 when I go to “mypage” with anything following the pagename, like so: http://example.com/mypage/foo. Because your RegEx pattern is ^category/([^/]+)/?, so the URL you should have visited is http://example.com/category/foo. But then, you shouldn’t use category because that “base” is … Read more

Add custom URLs to WordPress’s XML sitemap

Sitemap Provider It’s possible to create a so called custom sitemap provider and register it with wp_register_sitemap_provider(). It’s helpful to look at the core setup, e.g. for the WP_Sitemaps_Posts provider and also the dev notes. Basic Example – Sitemap with custom URLs Here’s a very basic example that adds the wpse provider that extends WP_Sitemaps_Provider, … Read more

Allow single quote in URLs

WordPress will strip off special characters, since they can cause issues when writing to the database. It’s best practice to avoid using special (reserved) characters in URLs, as they can and will break when passing them around. Case in point, see your own post and the cutting off of the URL after the ‘.

I need to generate the CSS for my plugin from a function, how do i map a request to a function in the front-end?

This is forked from something I wrote for a similar requirement. empty( $_GET[‘my-css-var’] ) || add_action( ‘plugins_loaded’, ‘wpse_59089_css’ ); function wpse_59089_css() { header( ‘Content-Type: text/css’ ); // Aggressive caching to save future requests from the same client. $etag = ‘”‘ . md5( __FILE__ . $_GET[‘my-css-var’] ) . ‘”‘; header( ‘ETag: ‘ . $etag ); header( … Read more

How can I extract the URL of a link from a post?

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 https://bar.tld”; $urls = wp_extract_urls( $content ); print_r( $urls … Read more

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