INSTRUCTION
stringlengths
11
999
RESPONSE
stringlengths
0
999
SOURCE
stringlengths
16
38
METADATA
dict
Photo gallery with Featured Images First, I need to ask if it's possible to create a photo gallery only with the featured images of the latest 6 posts? I assume it is possible but just want to make sure. I don't have much experience working directly with the wordpress gallery so could someone point me in the right direction for accomplishing this? Any plugin with similar functionally or tutorial will do.
$query = new WP_Query(array('posts_per_page' => 6, 'meta_key' => '_thumbnail_id')); while($query->have_posts()) : $query->the_post(); the_post_thumbnail(); endwhile; This code gets 6 latest posts which have featured image available & show those 6 images on the page. It will skip those posts where there is no featured image set even if they are newer. This will probably get you started. You should read the codex pages for `WP_Query` & `the_post_thumbnail`
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "post thumbnails, gallery" }
Wordpress widget/sidebar dividers? I have a widget sidebar, but I'd like dividers between them. I can achieve this in CSS using boring borders, but I have a png image I'd rather use instead. Is there a way to insert a divider after each widget item? (apart from the last one of course). I can do this in jQuery quite easily but I'd rather do it in the template file if at all possible I'm guessing it's something for the functions file or where I register the sidebar? Thank you
'after_widget' => '', As far as I know, thats the best way to do it
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "php, widgets, sidebar, list, register sidebar" }
Pretty Link Lite Plugin on WP Multisite I have a subdirectory install of the WP multiste and I'm trying to use the Pretty Link Lite Plugin to create shortlinks. I'm also using the MU domain mapping plugin to map each subdirectory site to a domain name. The pretty link manager creates shortlinks such as: domain.com/shortlink //base domain domain.com/sub/shortlink2 //subdirectory domain Is there any way to create a shortlink for: mappedDomain.com/shortlink as you would expect this plugin to accomplish?
look in your domain mapping options. Did you activate "Redirect administration pages to site's original domain (remote login disabled if redirect disabled)"? If so uncheck this and use the mapped domain name for the admin section (I have checked point 2+3 which is Permanent redirect and User domain mapping page and the other options are unchecked.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "multisite" }
Htaccess redirect from '/%postname%.html' to '/%postname%' I have a Drupal 5.x based travel review site which I'm moving over to Wordpress 3.x (same domain name). The Drupal site is structured like this: * `www.example.com/travel-guides` (these are top-level pages) - these are only a handful. * `www.example.com/<filename>.html` (filename is the name of a place / attraction etc). - makes up for bulk of the content in the site. In WordPress the setup is fairly straightforward. All content follows a simple permalink: www.example.com/postname How do I set a rule in .htaccess to bulk redirect all the pages? There are over 600 pages and I don't want to manually set redirect rules for all of them.
Above the WordPress rewrite rules add: RedirectMatch permanent ^/([^/]+)\.html$ /$1 That will catch `example.com/foo.html` but not `example.com/travel-guides/foo.html`. To catch all URLs ending with `.html` remove the first `^` from the pattern. To redirect all URLs ending with `.html` except those in `travel-guides` you need mod_rewrite: RewriteEngine On RewriteBase / RewriteCond %{REQUEST_URI} !^/travel-guides/ RewriteRule ([^/]+)\.html$ /$1 [L,R=301]
stackexchange-wordpress
{ "answer_score": 3, "question_score": 3, "tags": "redirect, htaccess" }
page not found in Chrome, but found in Firefox I use .html on PAGES plugin, and this works fine for me in Chrome and Firefox. However, Internet Explorer displays "page cannot be found". Why would one browser not display a page, but two others find it? Problem pages are: * < * <
You are sending a very confusing response: HTTP/1.1 301 Moved Permanently Date: Sat, 20 Oct 2012 12:33:06 GMT Server: Apache X-Powered-By: PHP/5.3.13 X-Pingback: Keep-Alive: timeout=5, max=100 Connection: Keep-Alive Content-Type: text/html; charset=UTF-8 After that the regular page content follows. So in your first line you tell the browser to look elsewhere for the content. But you don’t say where, there is no `Location` header. And then you send the content? Fix the HTTP header: send a proper status code (`200`), or a `Location` header with an URL for the new address.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "404 error" }
Why isn't WordPress part of Framework Interop Group? Are there any technical reasons that prevent WP to be part of Framework Interop Group?
Yes, WordPress's maintains backward compatibility (spaghetti), it would not be feasible to adhere to PSR-0 and rename everything, which is somewhat unfortunate for the long-term, with regards to FIG. That being said it's possible to adopt it for plugins and themes, there is a trac about it here: <
stackexchange-wordpress
{ "answer_score": 12, "question_score": 13, "tags": "php, coding standards" }
Posts in multiple Categories different single.php I am smashing my head against some code. Here is the situation: I have one post in 3 different categories, this post has to be visible in "category 1" with the single1.php, in "category 2" with single2.php and in "category 3" with single3.php. Obviously the 3 single.php pages have a different template inside. For example the single1.php shows pictures and the_content(); single2.php shows pictures and comments; single3.php shows the reviews. I know that in single.php I can use the if/else but I cannot figure out if the same post is in 3 different categories. Any help please?
Instead of making it category specific you could use post formats and use different content-templates. In single.php you can write <?php get_template_part( 'content', get_post_format() ); ?> Then create different post formats add_theme_support( 'post-formats', array( 'withpictures', 'withcomments' ) ); Then create different post templates content-withpictures.php, content-withcomments.php When creating content the chosen post format will determine the template.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 4, "tags": "theme development, categories, pages, single, hacks" }
Set user role based on invitation code I'm working on a site where I'd like anyone to be able to sign up, but people who sign up with an invite code would automatically be promoted to a role with more privileges. I'm aware that there are plugins that handle invite codes, but so far I haven't found any that will do quite this. For my purposes, one invite code used by many people would work best. I'd be sending out the invite code to a mailing list, and I'm not _that_ concerned about limiting access.
This is one way to do it add_action('user_register', 'set_custom_default_role') function set_custom_default_role($user_id) { // Maybe get available referral codes from database & compare them against the one available if(true) { $user = new WP_User( $user_id ); $user->set_role('custom-role-slug'); } }
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "user roles, signup" }
Get rid of Wordpress category, tag and author archives? I have searched the net with no success on what should be an easy thing. I have a highly customized blog with pages, sub pages and posts. While I rely heavily on the use of categories and tags I don't want them to be viewable in a url. The same goes for authors and date categories. Basically I wan't to throw a 404 error if someone tries to access these pages. Can someone point me in the right direction? Thanks! The following should not be accessible: * `example.com/category/books/` * `example.com/tag/ebooks/` * `example.com/author/dickens/` * `example.com/2012/10/`
building on chrisguitarguy's answer here is a quick snippet you can drop in your theme's functions.php file to do job add_action('template_redirect', 'wpse69948_archive_disabler'); function wpse69948_archive_disabler() { if(is_tag() || is_category() || is_date() || is_author()) { global $wp_query; $wp_query->set_404(); } }
stackexchange-wordpress
{ "answer_score": 7, "question_score": 11, "tags": "categories, functions, archives" }
How to display update message only to admin How can I show the update message only to super admin in the network wordpress ? I don't want the other admins/users see the update message that shows the current version. Is there any plugin to do this or I have to changes the core?
Create your own plugin with this code or put this in theme's functions.php add_action('init', 'remove_update_notification', 1) function remove_update_notification() { if (!current_user_can('manage_network')) { // checks to see if current user can update plugins add_action( 'init', create_function( '$a', "remove_action( 'init', 'wp_version_check' );" ), 2 ); add_filter( 'pre_option_update_core', create_function( '$a', "return null;" ) ); } }
stackexchange-wordpress
{ "answer_score": 3, "question_score": -1, "tags": "multisite, network admin, options" }
Let user subscribe to specific categories How could I let each user subscribe to a specific categories of his choice? I want to do something like reddit subscribe to categories? Is there any tutorial helps doing this?
You can give them this url This one if permalinks are enabled < Replace the site url & also the cateogries id or slug with the correct one ## UPDATE IN RESPONSE TO COMMENT Display a list of categories to the user maybe with `wp_dropdown_categories`. Save the id of the category the user subscribed to in the database by using the function `add_user_meta()` or `update_user_meta`, then on the template on which you want to show the posts use `WP_Query` to retrieve all the posts. If you don't know the functions, check out their reference on codex, it's easy to find on google
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "plugins, plugin development, plugin recommendation" }
Stop wordpress from creating multiple size images I want wordpress to stop making multiple size images cause it's going to eat up my storage space. So I went Settings > Media and then set all the sizes to 0. When I uploaded a new image it still is making 2 copies for example: achannel.jpg achannel-346x288.jpg although they are both full size images so why does it need to create another full size image?
add_filter('intermediate_image_sizes_advanced', 'filter_image_sizes'); function filter_image_sizes( $sizes) { unset( $sizes['thumbnail']); unset( $sizes['medium']); unset( $sizes['large']); return $sizes; }
stackexchange-wordpress
{ "answer_score": 6, "question_score": 3, "tags": "thumbnails, images" }
Showing posts from 4 categories along with all latest posts Currently in my theme i am running the default **query** that pulls all **recent posts/latest entries/latest published posts** . But i am looking for something more complex like i am gonna **setup** two sections . One is for all the **latest entries** and the other one is for the four **sub-sections which will show posts from 4 selected categories** but the posts of those selected categories wont be showed in the latest entries i mean the first query which was pulling all posts will **exclude** the posts of 4 **selected categories** . cause there will be duplication .. but i don't know the exact query/wp-query code for this type of setting . .
You must first do the 4 queries for selected categories and while looping through them remember the IDs. Save them in an array. Then when pulling latest posts just add the `post__not_in` parameter with all the IDs you want to exclude. You need 4 queries that look somewhat like this: $args = array( 'category_name' => 'category1' ); $loop = new WP_Query($args); while ($loop->have_posts()) : $loop->the_post(); //do something $excludeIDs[] = the_ID(); endwhile; wp_reset_postdata(); and then one something like this: $args = array( 'post__not_in' => $excludeIDs ); $loop = new WP_Query($args); while ($loop->have_posts()) : $loop->the_post(); //do something else $excludeIDs[] = the_ID(); endwhile; wp_reset_postdata(); That should get you started. If you need any other help, just ask.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "wp query, query" }
Ordering posts by metadata In my plugin, I use these instructions to obtain a list of posts: $args = array( 'numberposts' => -1, 'offset' => 0, 'meta_query' => array( array( 'key' => 'metadata1', 'value' => '80', 'compare' => '<=', 'type' => 'UNSIGNED' ), array( 'key' => 'metadata2', 'value' => '4.6', 'compare' => '<=', 'type' => 'DECIMAL' ), ), 'post_type' => 'post', 'post_status' => 'publish', 'suppress_filters' => true ); $posts = get_posts($args); foreach ($posts as $post) { // some work on $post } How can I order these posts by `metadata1` ascending or by `metadata2` ascending? (Note that `metadata1` is an unsigned integer number, and `metadata2` is a decimal number.)
Try meta_value_num 'meta_key' => 'metadata1', 'orderby' => 'meta_value_num' Add these 2 parameters to $args. This does the sorting considering metadata1 as numeric
stackexchange-wordpress
{ "answer_score": 6, "question_score": 1, "tags": "plugin development, custom field, get posts, post meta" }
How to add "supports" parameter for a Custom Post Type? Is there a way to add support for a custom feature for a custom post type, after it has been created? I know how to create a custom post type using register_post_type(), and how to use the supports parameter to specify what the CPT should support; 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt' ,'headway-seo') But for the situations when the CPT is being registered by a plugin or theme, is there a way to 'inject' support elements (manipulate the support array) of the CPT after it has been registered, using a WP hook/filter?
Yes, there's a function called `add_post_type_support` Hook into `init` \-- late, after the post types have been created -- and add support. Adding support for excerpts to pages for instance: <?php add_action('init', 'wpse70000_add_excerpt', 100); function wpse70000_add_excerpt() { add_post_type_support('page', 'excerpt'); }
stackexchange-wordpress
{ "answer_score": 12, "question_score": 11, "tags": "custom post types" }
Display price range on woocommerce product variations I am working on an online store using Woocommerce, many products have variations in size and price. Is there a way to have the range of prices (highest to lowest) of the variations on the product page?
try it like this: /** * This code should be added to functions.php of your theme **/ add_filter('woocommerce_variable_price_html', 'custom_variation_price', 10, 2); function custom_variation_price( $price, $product ) { $price = ''; if ( !$product->min_variation_price || $product->min_variation_price !== $product->max_variation_price ) $price .= '<span class="from">' . _x('From', 'min_price', 'woocommerce') . ' </span>'; $price .= woocommerce_price($product->get_price()); if ( $product->max_variation_price && $product->max_variation_price !== $product->min_variation_price ) { $price .= '<span class="to"> ' . _x('to', 'max_price', 'woocommerce') . ' </span>'; $price .= woocommerce_price($product->max_variation_price); } return $price; } source: <
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "plugins" }
How to edit caption for images and exclude it from excerption query? I have 2 questions for caption for images: \- how to edti them with bold, italics and so on? I do it, but it doesn't work. \- if the image is first, how to exclude caption from excerpt in query especially for frontpage?
For your first question- HTML support for captions was a new feature in wordpress 3.4, if you have any version prior to that, it won't work I'm not sure if i understood your 2nd question, but to exclude the caption from not displaying on the page, you'll have to either delete the caption from the image or edit your theme's template files ## UPDATE First if the image was inserted in the page content, it is inserted in the form of a shortcode, so you can use the filter `img_caption_shortcode` to override the default shortcode output. If it's set as featured image, instead of using `the_post_thumbnail`, use `get_post_thumbnail_id` & generate the `img` tag yourself & skip the caption. Next to permanently disable the captions functionality(you already cleared you don't want to do that), you can use this `add_filter( 'disable_captions', '__return_true' );` If you want a WYSIWYG editor in captions, there isn't any hook for that. You'll have to code it yourself
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "images, captions" }
How to have changes made in media library to be reflected on posts/pages I have recently invested a bunch of hours updating the alt text of all the images in a media library, only to realise that the changes are not reflected on posts/pages. Whoops! Is there any way to force these changes across? Or have I no choice but to edit each page manually? Hope someone has good news for me! Thanks
If the image is the featured image or some image inserted via a shortcode, then those changes will reflect automatically(if they don't, it's your theme's fault, you'll have to edit your theme) If the image is inserted into the post content, yes you'll have to go through each page/post & manually do the changes. Though updating them in media library assures that they will be inserted right the next time you insert the same images.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 2, "tags": "media library" }
Excerpt Word Count The code below from WPSnipps provides an excerpt character counter, but I'd like to count **words** instead. Does anybody have an idea of how to do this? // Excerpt character count function excerpt_count_js(){ echo '<script>jQuery(document).ready(function(){ jQuery("#postexcerpt .handlediv").after("<div style=\"position:absolute;top:0px;right:5px;color:#666;\"><small>Excerpt length: </small><input type=\"text\" value=\"0\" maxlength=\"3\" size=\"3\" id=\"excerpt_counter\" readonly=\"\" style=\"background:#fff;\"> <small>character(s).</small></div>"); jQuery("#excerpt_counter").val(jQuery("#excerpt").val().length); jQuery("#excerpt").keyup( function() { jQuery("#excerpt_counter").val(jQuery("#excerpt").val().length); }); });</script>'; } add_action( 'admin_head-post.php', 'excerpt_count_js'); add_action( 'admin_head-post-new.php', 'excerpt_count_js');
Sorry for reading wrong your question @siouxfan45! here is the right answer: just a little improvement in your code and you can count words! just change these two lines: jQuery("#excerpt_counter").val(jQuery("#excerpt").val().length); to this: jQuery("#excerpt_counter").val(jQuery("#excerpt").val().split(/\S\b[\s,\.\'-:;]*/).length - 1); Words with single quote like "don't", "it's", "I'd", "won't"...will count as two! If you want them to count as a single word, then you will want to change the `.split()` to this: .split(/\S+\b[\s,\.\'-:;]*/) Hope I'm right this time!
stackexchange-wordpress
{ "answer_score": 3, "question_score": 3, "tags": "excerpt" }
Sort post's categories by ID I have a blog in which several post's categories have to be outputted first before other categories. Those categories have lower ID compared to other categories. I am using `get_the_category_list` but it is not working as I expected. Makes me confused because I remember a theme doing this very well. Can someone point me in the right direction? Thanks! <?php get_the_category_list( array( 'orderby' => 'ID', 'order' => 'ASC' ) ); ?>
You're using wrong arguments for `get_the_category_list` function. The function you should use for this is `wp_get_object_terms` <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "categories" }
Removing default image size list in Media Box !Removing default image size list in Media Box I trying to remove unused image size (Thumbnail, Medium, Large) in MediaBox Any function can i use in functions.php ? or some trick ? PS : I know i can use jQuery trick but any better function to use ?
Exactly the same code as Mridul, but different filter: function wp_70048_remove_image_sizes($sizes) { unset($sizes['thumbnail']); unset($sizes['medium']); unset($sizes['large']); return $sizes; } add_filter('image_size_names_choose', 'wp_70048_remove_image_sizes'); Tested with WP 3.4.2 !removed image sizes
stackexchange-wordpress
{ "answer_score": 5, "question_score": 5, "tags": "functions, images, media, list, filters" }
How to stop wp_postmeta from being called on archive and search pages? Currently, when I load a search or result page, it queries the `wp_postmeta` table which is leading to the page taking ages to load. I realise this is a result of this table being huge (70k rows), and because of how much data is loaded into the cache. Is there a way to stop `update_post_caches` from being called when these pages are loaded, and then send custom (and more efficient) queries to the database once the template has been loaded? !enter image description here
add_filter('pre_get_posts', 'customize_query'); function customize_query($query) { if($query->is_main_query() && ($query->is_search() || $query->is_archive()) { $query->set('update_post_meta_cache', false); $query->set('update_post_term_cache', false); } } Then wordpress will make 2 less queries for those pages & then you can use the $wpdb object to write custom queries.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "post meta, meta query, optimization" }
how can I get seperate the HTML in the_content(); output? I want to be able to seperate the first image form the post into a `<div>` tag and link it to the post page and be able to add html around the post text elements seprately. Any help is greatly appreciated This is what I have tried query_posts('posts_per_page=1&tag=food'); while (have_posts()) : the_post(); echo "<li class='homePost'>\n"; echo the_content(); echo '<a href="' . get_permalink() . '">'; the_title(); echo '</a>'; echo "</li>\n"; endwhile;
Look at this snippet from CSS-Tricks. It gets the first image from a post.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "wp query, the content" }
RSS feed validity and Google Adsense I want to use Google Adsense code snippets in my blog posts, so in my single.php. However, when I do so, then my RSS feed becomes invalid because of the javascript code in the content and the feed won't be updated anymore. Is there ANY way to fix this? I still have the Google Adsense code in the sidebar where it's not causing any issues. I've seen lots of blogs that have Google ads in their blog posts and a functioning RSS feed, so it seems to be possible, but how? Or rather, why is it causing problems in my case? I've done a looooooooot of research, but couldn't find ANY information about this issue. I think that means that it's not a very common problem. I really hope somebody can help me with this BIG problem. Would something like this work? < For reference, here's my website: < Here's my feed: < Thanks a lot in advance!
Do not paste the Adsense code into the blog posts. Use a plugin instead. Sample Plugin: <?php /* Plugin Name: Zoomingjapan Adsense */ add_filter( 'the_content', 'zoomingjapan_adsense' ); function zoomingjapan_adsense( $content ) { if ( is_feed() or ! is_singular() ) return $content; $adsense = '<adense code, replace that!>'; // remove all existing script elements $content = preg_replace("~<script[^>]*>.+</script[^>]*>~i", '', $content ); return $content . $adsense; } Usage: * Change the content of the variable `$adsense` to whatever you need. * Put the file into `wp-content/plugins/`. * Activate it in `wp-admin/plugins.php`. That’s all.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "feed, feedburner, adsense" }
WooCommerce with thousands of products - site is very slow - optimize db queries? So far I've got around 8,000 products in my WooCommerce and the product page on the front end takes several seconds to load, even after caching. My VPS host says that I should have multiple databases. Is that the right method and if so, how is it possible? Any suggestions on speeding up my database queries or simply speeding up the front end would be great.
This is really a server question and not particularly Wordpress. You're running into a MySQL server speed bottleneck at 1and1. Sorry, but they're well known as a slow shared host, and for that reason I doubt their VPSs are any better. Caching and a CDN will only do so much for you. You need more horsepowwer in the form of a better and faster MySQL server, and if you're already paying for a VPS, move to a better VPS host, like Media Temple. Once there, with root access, you can use a utility such as < to log and analyze the performance of the MySQL server and adjust server memory and database query cache parameters in the configuration file my.cnf. You will also be able to adjust apache - in httpd.conf - to handle high loads. There is little sense in trying to optimize the database queries made by Woo Commerce or Wordpress; any changes made will need to be made again after updates.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 3, "tags": "database, mysql, plugins, performance, vps" }
Use get variable when rewritten url in wordpress I have many pages which have a lot in common. They are supposed to display the same things but according to their own categories. The logical way to implement this would be to pass a variable through the url and display the info according to it. The only problem is that my wordpress urls are rewritten... I search this site before asking and I know there are posts around here related to that matter but they don't help me as they refer to some obscure regex I just can't associate to my own case. Not to mention some unexplained references to "tags" and "rules" which are quite beyond me. I reallly tried to learn from theses posts but I couldn't make use of them. Basically, my urls are rewritten and I need to add a single variable to this: " I don't know how to send the "mycategory" variable AND I don't know how to retrieve it. Any help would be appreciated.
What I did is rewrite url's in order to display the categories on them. After that, I just extracted them with the function "get_category_by_path". It allowed me to use the url info without having to inject and extract any custom variable. Thank you.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "categories, terms" }
wp-admin does not redirect to dashboard I have a weird problem, which I could not solve yet. I installed wordpress 3.4.1 and made an own template. I use one plugin - qTranslate. Everything is fine on my local copy and also on my dev copy dev.mysite.cz. When I copied wordpress and log in on the main site, < the dashboard does not show up. Instead I only get the homesite with the administration panel on top of the page. The only difference I can so far tell is in the wp-config.php file. In production mode I have this two more directives in it: /** debugging mode */ define('WP_DEBUG', false); /** Localisation */ define('WPLANG', 'cs_CZ'); Any advice will be very appriciated. Thanks
The problem was in .htaccess. There was an old global .htaccess file (from the old website) besides the wordpress one which was hidden on the sever (by admins of the hosting company) which rewrite rules harmed the ones in wordpress. I actually had to contact the admins and ask them to remove those rewrite rules.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "wp admin, dashboard" }
dynamic sidebar in front page I am developing TwentyTen child theme and wish to display dynamic sidebar on front page, but something is not quite right. I modified `loop-page.php`: <div class="entry-content"> <?php dynamic_sidebar('promotion-sidebar'); ?> //ADDED LINE <?php the_content(); ?> <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?> <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="edit-link">', '</span>' ); ?> </div><!-- .entry-content --> At first I was invoking it inside `is_front_page` conditional statement but then to double check issue I decided to call it on every page. And guess what it appears on every single one except on the one I want: **THE FRONT PAGE** _**Edit: I am using Sidebar Template for my static front page._** I just don't get it. Any help appreciated.
`loop-page.php` is the wrong context for what you are trying to do. If you want it to appear on the home page, then you need to edit `loop.php`, so in your child theme you can either create a file called, `loop.php` ...which should take precedence over the `loop.php` found in the parent TwentyTen theme or better yet create a file called, `loop-index.php` ...which will take first priority over the above. By doing this and NOT creating a `loop.php` we will allow the `loop.php` file in the parent theme to act as a fall back in case something goes wrong. Hopefully that makes sense. In summary, you want to create a `loop-index.php` file (best option). You can simply copy the contents of what you find in `loop-page.php` over to this `loop-index.php` file to give you the basic framework for your template, then you can modify the template to your liking.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "widgets, frontpage" }
Projectmanager Internal Link Code Location I'm working with the ProjectManager Plugin (by Kolja Schleich) and i've exausted myself trying to find the code that controles the Internal Link Form field. Does anyone out there in the magical world of the internet know where this code is located? UPDATE: < is the plugin UPDATE: The reason I wish to access the code is that it is currently displaying as a checkbox list of all of the fields in the linked table, I wish to modify it so that there is a dropdown option as an extra form field.
Not 100% certain but you could check admin/dataset-form.php around line 92 <?php elseif ( 'project' == $form_field->type ) : echo $projectmanager->getDatasetCheckboxList($options['form_field_options'][$form_field->id], 'form_field['.$form_field->id.'][]', $meta_data[$form_field->id]); ?>
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugin development" }
Given the ID of a product in woocommerce, how can I get its URL? Say I have the ID of a product in wooCommerce; can I generate its URL somehow? (example /shop/fresh-apples)
Products in WooCommerce are a custom post type, so this should work: $url = get_permalink( $product_id ); You can treat that `$product_id` as a postID (that's what it is), so you can use it with other normal WP functions, like: echo '<a href="'.get_permalink($product_id).'">'.get_the_title($product_id).'</a>';
stackexchange-wordpress
{ "answer_score": 40, "question_score": 28, "tags": "plugins" }
Switching off shipping in WP-eCommerce My client needs to work out the shipping only after someone has made a "purchase" on his site so by default, this option needs to be switched off and yet, when I switch shipping off, I still get shipping options coming up everywhere. I could hide this with CSS but if the option to switch off shipping is there, I would like to be able to use it. Is there something else I need to perhaps switch off/set? Thanks
Tried here? _settings->store->presentation_ **:Display per item shipping**
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugin wp e commerce" }
Can't access wp-admin When trying to login one of my WP installs (regular WP 3.4.2-no multisite), I keep being redirected to the `wp-login.php` file. I've checked nearly everything: * Password is correct and changed...nothing * Reset to a default theme...nothing * Deactivated al plugins...nothing * Reuploaded my `wp-login.php` file...nothing * Checked the `.htaccess` files...nothing * `wp-config.php` still looks the same. * Erased my browser data and used an other browser... Still nothing. * Completely overwritten every WordPress file with a fresh download install. What else could this be? I didn't make any upgrades to the code.
I've solved the problem by putting back a backup of the evening before the problem.The cause of this problem will never be known. Server logs (access and error logs) don't give a clue. WP_debug doesn't give a clue. Every FTP file has been checked and overwritten. The problem must be in the database somehow, but the wp_options table shows no errors. Thanks for thinking with me. It's been a valuable lesson. I hope this topic can be a help for anyone facing the same problem. Normally the list in my question should solve their problem.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "wp login form" }
Change admin startpage to Pages-page? When you login to the admin you see the Welcome page by default. A client of mine requested to see the "Pages" page by default, he had seen it somewhere else. Is this possible, and if so, how? Tried searching but found nothing relevant, didn't find it in the settings either.
This should work for you if you put it in your themes functions.php file, but you may want to modify the conditions, and the url to redirect to depending on your set up. function loginRedirect( $redirect_to, $request, $user ){ if( is_array( $user->roles ) ) { // check if user has a role return "/wp-admin/edit.php?post_type=page"; } } add_filter("login_redirect", "loginRedirect", 10, 3); Here's a link containing more info about using the `login_redirect` filter: < There's also a few login redirect plugins floating around if you do a google search.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 3, "tags": "pages, admin, homepage, customization" }
Get Order of Meta Box in a Page/Post I'm using the Posts 2 Posts plugin specifically, but I think this applies to any meta box. I have three Posts 2 Posts metaboxes on the side: "Related Case Studies", "Related White Papers" and "Related Videos". I'd like the client to be able to drag these, and have the metabox order correspond to the order they appear on my sidebar. I can do all the backend code to sort properly on the page, I just need to retrieve the value of the metabox order on a per page basis. Meaning if the client dragged the "Related Videos" metabox above the "Related Case Studies" metabox, I'd be able to grab a value to be aware of that on the page itself and output it exactly like it looks. Is this possible? Thanks.
It's not that hard: There's a user Meta entry for that. You can not only retrieve the order, but also which ones are hidden (just to get one step further). # Meta Box Order $meta_box_order = get_user_meta( wp_get_current_user()->ID ,sprintf( 'meta-box-order_%s', get_post_type() ) ,true ); # Hidden Meta Box $meta_box_hidden = get_user_meta( wp_get_current_user()->ID ,sprintf( 'metaboxhidden_%s', get_post_type() ) ,true );
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "pages, metabox, sidebar" }
Redirect users away from Admin breaks ajax Tried to make a simple redirect for some users I don't want to access the wp-admin/, so I did this code: function no_admin_access() { if ( !current_user_can( 'delete_posts' ) ) { wp_redirect( site_url( '/' ) ); exit; } } add_action('admin_init', 'no_admin_access'); But when I then try to make a ajax request with those users, the that is also redirected so I never get to admin-ajax.php Anybody who has a good work around for this ? Thanks. AJAX Code $.ajax({ type: 'POST', url: MyAjax.ajaxurl, data: { action: 'mux_ajax_delete_pix', pid: $this.attr('data-id') }, success: function(){ $this.parent().fadeOut(); } });
You can and a check for the `DOING_AJAX` constant which is defined on an Ajax in your conditional check: function no_admin_access() { if ( // Don't do this for AJAX calls ! defined( 'DOING_AJAX' ) // Capability check && ! current_user_can( 'delete_posts' ) ) { // Redirect to home/front page wp_redirect( site_url( '/' ) ); // Never ever(!) forget to exit(); or die(); after a redirect exit; } } add_action( 'admin_init', 'no_admin_access' );
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "wp admin, ajax, wp redirect" }
Custom Taxonomy Taxonomies of Same Name point to first created URL I created a Custom Post type and in that custom post type have a hierarchical taxonomy (categories). Here's an example of the categories I made: Hats - Mens - Womens Shoes - Mens - Womens The problem is that when I go to the "Mens" sub-category of the "Shoes" Main category it goes to the Mens category of the "Hats" category, i'm guessing it's because the URL of the two is the same. What is the best way around this problem?
This is a problem with wordpress that happened to me as well. If the titles of 2 terms (even if they are from different taxonomy), wordpress will not create another term in the database, instead link the previous term to taxonomy. If you look in your database, you'll find only 1 term with title "Mens" which will be a child of both Hats & Shoes. Also if you try to change the title/slug of one of those terms, wordpress will change the corresponding term under other taxonomy too. You can't separate them like this right now Interestingly, if the terms you created were "Mens" & "mens", wordpress takes the slug of the 2nd to be "mens-2" & then it works as normal. I don't know if it's intentional but this thing was very frustrating the first time i found out.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, categories, custom taxonomy" }
Is there any sort of theme dependency management? I'm developing a Wordpress theme with a few other individuals and am running into a problem where I add a plugin and then I have tell the other developers about the plugin I installed and the settings I set for the plugin so that the theme works. I was wondering if there's a way to associate plugins with a theme, so that when an individual receives the theme, the theme knows which plugins it needs and can automagically install them and their correct versions. I suppose I'm looking for some sort of dependency management for Wordpress themes. Is there something like that out there?
There isn't any such feature directly in wordpress but there is a php library that do allow this kind of behaviour. Can't comment on how/if it works as I haven't tried it yet but it looks like it does the job. You might find it useful <
stackexchange-wordpress
{ "answer_score": 9, "question_score": 12, "tags": "plugins, theme development, wp dependencies" }
Does WP, php, or a current framework (woofoo / genesis, etc). Offer a way to schedule text / bg color changes? I would like to build a site for a religious group that follows a Church calendar year that highlights seasons by different colors. Is there a way with existing WP / php / css / framework to schedule a different color profile for a theme based on the date? casey
You could just create different style sheets for each color profile, and load those depending on which month it is. Here's a basic example showing how you could load a halloween.css file for october, and an xmas.css file for december. The code below would go in your themes functions.php file: add_action('wp_enqueue_scripts', 'seasonalCSS'); function seasonalCSS() { // register stylesheets to be loaded safely wp_register_style('halloween', get_stylesheet_directory_uri() . "/halloween.css"); wp_register_style('xmas', get_stylesheet_directory_uri() . "/xmas.css"); switch(date('n')) { case 10: // if it is october... wp_enqueue_style('halloween'); // load halloween.css break; case 12: // if it is december... wp_enqueue_style('xmas'); // load xmas.css break; } }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "themes, framework" }
WP_Query search by multiple meta key and distance I am having two meta keys, longitude and latitude, and what I am trying to do is the equivalent of the google store location algorithm for distance, in wp_query: > SELECT id, ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-122) ) + sin( radians(37) ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < 25 ORDER BY distance LIMIT 0 , 20; What I am trying to do, is get a list of custom post types (stores) that contain long/lat (custom fields), and having an x distance (it's for a store locator, like google's example). I have already done it with $wpdb way, but I am looking for a wp_query because I want the paging and the extra filtering by using/removing an add_filter() directive to the page. Is it possible to execute such complex query, or should I stick to $wpdb method?
You can do that. There are filters available in WP_Query that enable you to modify the query just as you like. The filter `posts_clauses` filters all of the parts of the query together. There are also filters specific to the parts of the query too. The best way to know about them is, search `posts_clauses` in "wp-includes/query.php". Just 3-4 lines before this filter should be a series of filters to filter out the full query part-by-part. The filter tags are self explanatory & you can experiment with them to see which combination works out the best for you
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "wp query, wpdb" }
If post content exists (any post content), do not display featured image If post content exists, do not display featured image, if it does not exists, then display featured image or url. So, basically I want featured image to be displayed only if nothing else in post content to be displayed. Thanks!!!!
Just check the raw post content without any filters: if ( "" === $post->post_content ) { the_post_thumbnail(); } else { the_content(); }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "post content" }
Display the popular tags by default in the backend post edit page (without having to click on the link that displays them) I know there should be a way to call the AJAX function by page load but I've been looking at how to do this for hours and can't figure it out. Any help is appreciated.
I fixed it by bypassing the script.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "posts, admin, tags" }
Removing Title Tag from Thumbnails I'm currently adding thumbnails to my page with: `<?php the_post_thumbnail( 'category-thumb' ); ?>` and this in the fuctions.php: if ( function_exists( 'add_image_size' ) ) { add_image_size( 'category-thumb', 200, 142 ); } How do i stop the title tag from being added?
This filter will remove it completely from all images, you can add a conditional to only effect certain images. function remove_img_title($atts) { unset($atts['title']); return $atts; } add_filter('wp_get_attachment_image_attributes','remove_img_title'); * * * Instead if you want to use `<?php the_post_thumbnail( 'category-thumb' ); ?>` You can pass it an empty title using the second `$attr` so your title tag will look like `title=" "`. It would be: $default_attr = array('title' => ' '); the_post_thumbnail('post-thumbnails', $default_attr);
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "images, post thumbnails, thumbnails" }
Empty "Forums" page BuddyPress site wide forums - bbPress The main "Forums" page where all forums are supposed to be listed is empty. !enter image description here What have I missed here or the combination of BuddyPress and bbPress caused this page not to work anymore? I have followed the installation guide here <
Ok, I figured it out In BuddyPress installation guide, it says I needed to delete "Forums" WordPress page so I did. Turn out that "Forums" page held on to mywebsite.com/forums permalink although it was already trashed. So I went into phpMyAdmin and change the slug of the page to forums1 and guid to mywebsite.com/forums1 (I'm not sure if changing guid is necessary) and then created a new page with name "Forums". Now this new page can have permalink mywebsite.com/forums I can insert shortcode `[bbp-forum-index]` as Sarah Gooding pointed out here Alternatively, I believe you can bring the "Forums" page back to life (Hi BuddyPress, why should we delete the "Forums" page in the first place?) and choose default template (just don't wanna mess with BuddyPress templates) and insert the same shortcode.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "buddypress, bbpress, forum" }
Wordpress page edit does not save selected template The feature did work in the past however pages now seem to default to 'Default Template'. I can see my available page templates in the drop-down on the Page edit page, however after saving the admin simply shows 'Default Template' again. I have tried disabling all plugins as well as remaking some of the templates, however the behaviour continues. Any ideas? Note: I'm using latest self-hosted WordPress. Update: After some digging it would appear that I am getting 'Table xxx/wp_postmeta' is marked as crashed and should be repaired". However running repair through phpmyadmin does not fix the issue. Update: Rebuilt the table entirely, still have issue. (Originally posted this question here: <
Turns out this was an issue with my hosting. phpmyadmin although reporting operations as complete was not actually committing repairs / optimisations. Now querying why this is with the company. So the simple fix was indeed to simply repair + optimise the table.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 5, "tags": "pages, page template" }
Deregister a CSS file that comes with a plugin WPML plugin comes with its own CSS file. I want to get rid of all the CSS it contains, so I put everything between `/* */`. However I'll have to do that again when I'll update the plugin. Is there a way to "unload" a CSS file ?
You can use wp_dequeue_style function, with a wp_enqueue_script hook with priority higher than WPML's wp_enqueue_script hook. Put the following code into your functions.php: function dequeue_wpml_styles(){ wp_dequeue_style( 'wmpl_style_handle' ); } add_action( 'wp_enqueue_scripts', 'dequeue_wpml_styles', 20 ); REPLACE 'wmpl_style_handle' with the handle WPML registers/enqueues the style. **UPDATE** : I have just had a look into WPML and it looks that it doesn't use wp_enqueue_script to include language-selector.css, But the good news is that there is a constant which you can set to prevent loading of the language selector styles. Just add the line below to your functions.php: define('ICL_DONT_LOAD_LANGUAGE_SELECTOR_CSS', true);
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "wp enqueue style, wp register style" }
Wordpress Options-Theme STD (default) value does not work I'm using Wordpress Options Theme and I'm getting an issue. Here's the code: $options[] = array( "name" => __('Texto de bot&oacute;n de enlace a cotizaci&oacute;n',THEMENAME), "desc" => __('Inserta el texto que aparecer&aacute; en los botones de cotizaci&oacute;n',THEMENAME), "id" => "ns_custom_caps_quote_btn", "std" => __('Cotizar', THEMENAME), "type" => "text"); And when I reset to default, the input returns "a" instead of "Cotizar". Any suggestion? Thanks in advance.
Values set in the 'std' key of the array, 'std' => 'your default value' Are saved to the database on first initialization of the framework. Once you overwrite the default value and or remove the default value, even if left as a blank field, the default no longer applies unless you hit the "restore defaults" button.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, theme options" }
How do I list multisite users for the current site only I'm looking for a way of selecting the users for one site within a multisite set up. Can anyone tell me how to do this please? This is what I have at the moment: $user_search = $wpdb->get_results("SELECT ID, display_name, user_email FROM ".$wpdb->base_prefix."users"); but this selects all users across the multisite. Many thanks!
get_users function is the method you should use to query users, and by default it retrieves only users of the current blog in a multisite setup.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "multisite, multisite user management" }
How to change how many list item show in category generated by file edit-tags.php It's always been a pain in the @$$ to see only 20 item in category. If i have 30, it paged on 2 pages, i hate that. If WordPress had a preference for that. So the question, Hot to list ALL the category, whatever the number... if i have 200, list them all, no paging. I inspect edit-tags.php and could not find "show_item=20" of something like that The question, how to make edit-tags.php show 9999 item (or unlimited) of have a plugin to customize that without hacking the WP core file. * * * I think the magic is happening here, but changing 20 to 999 dont change anything add_screen_option( 'per_page', array( 'label' => $title, 'default' => 20, 'option' => 'edit_' . $tax->name . '_per_page' ) ); It's for product attribute in woocommerce.
It is absolutely not user friendly, but i have found it - after coding and reading 10-15 pages of plugin code that does exactly that. It is options in `Screen Options` slide-down menu (at the top of every screen). Keep that for future reference!
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "categories, plugins" }
Title tags show twice My Title tags same sentence show twice. please see it. how i can solve this problem . my site
Go to the header.php file in your template folder and make sure that between the title tags, there's only this code: <?php wp_title('');?> That should do the trick. This error is a combination of your template files with standard settings of the Yoast SEO plugin.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "title, wp title" }
How to change post format from Aside to Image for all posts? I have a blog where all the posts had the post format **_Image_**. This morning I see that somehow they have all been changed to **_Aside_**. I'm still trying to figure out how this happened, but in the meantime, how do I go about changing them all back to Image? Is this something I can do with a SQL statement or do I need to write a custom script to loop through all the posts and save them with the Image post format? And if a SQL statement would work, any thoughts on what that might look like? Thanks much, Mark
You can do this right in interface: 1. Select posts in need of change in admin post list screen 2. Select `Edit` in `Bulk actions` dropdown and press `Apply` next to it 3. Choose `Format` > `Image` in interface panel that appeared 4. Press `Update` to apply
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "mysql, post formats" }
Creating a full business website I have a webservice and I want to sell it and allow the customer to set it up through a website. I'm thinking to use WordPress to make this website, but don't know if it is possible or how to do it. Basically, my webservice needs some information from the customer to work. I mean, after buying our service, the customer will have access to a page and he/she will input some information and submit them (to our server, that will set up the service for that customer). I need the WordPress to save these input information and display them later, whenever the customer access and log-in my website. In other words, I need any user can: * Buy my service (public area) and then log-in to set it up (private area) * Save, update and delete input personal information (that only he/she can see/create/update/delete) Can I do this through WordPress? Any idea on how?
The answer is yes but you may need to use a combination of access plugins and custom post types to represent the data that your users are going to enter. Start with researching custom post types in the WP codex and then research some of the developing plugins to help speed up the process in the area - check out "podCMS" or "Types and Views". You should also check out the member access / subscription plugins starting with "role scoper" to help with the access. Just google for "wordpress membership" or "user access control" and you find 20 - 30 options. I am not sure if this helps but I hope it is a start in the right direction.
stackexchange-wordpress
{ "answer_score": 0, "question_score": -1, "tags": "plugins, user registration, web services" }
Unprotected page appears protected when posted to Facebook (S2Member) I recently removed the restriction on the following page: < I can now view it without being logged in. However, if I post this URL to my Facebook wall, it shows the "Join" page, as if Facebook thinks I need to log in the view that content. I tried clearing Quick Cache and loading the page from a remote computer--it's definitely visible to all. Except Facebook apparently. Ideas?
remove the trailing slash and it works fine.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "facebook, s2member" }
Get plugin_dir_url() from one level deep within plugin I've written several plugins using the structure : /plugins/myplugin/myplugin.php /plugins/myplugin/class/class-myclass.php So as to take advantage of OO and overall structuring my code From within the class file there are times I need to get the URL of the base plugin... I have been using the following, but I'm sure there's a better way: $this->plugin_location = substr(plugin_dir_url(__FILE__),0, strrpos(plugin_dir_url(__FILE__), "/",-2)) . "/"; Another idea I toyed with was having an additional singleton class that stores all of the settings for the plugin and adding an abstraction layer via the class files. Any help is greatly appreciated.
In a subdirectory within your plugin directory you can use the following code: $this->plugin_location = plugin_dir_url(dirname(__FILE__));
stackexchange-wordpress
{ "answer_score": 21, "question_score": 15, "tags": "plugins, plugin development, oop" }
What are the critical theme files when building a custom theme? What are the critical files a theme MUST have to be a WordPress theme and validate properly?
< The bare minimum required is your index.php file and style.CSS file. Those two files alone are technically enough to run your entire theme. It's highly unlikely that you'll rely on those two alone. The above link gives you an in-depth look at both the minimum and recommended requirements. For example I run one theme with an index.php, functions.php, style.css and a loop.php and templates.php file. It's a complete custom job that relies on the heavy use of filters to create a modular way of delivering content with a minimal setup. You won't encounter themes like this very often, but it does illustrate the possibilities and power of Wordpress theming which don't always have to follow the norm. **Themes intended for release at the wordpress.org public theme repository however, follow a stricter set of guidelines, regardless of the above. This is more so to ensure consistency and interoperability when changing from theme to theme as people who use free themes often do**
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "theme development, themes" }
Find out if there is a available core update? I want to set up a function that notifies me when a core update is available. But i can't find any functions that check for updates. I have looked at list_core_updates() and it may be possible to check if it returns anything, but i don't know if that is smart.
There is `get_core_updates()`. Note that you might need to manually include admin file that declares it, if running in front end and such. Example use: require_once ABSPATH . '/wp-admin/includes/update.php'; print_r( get_core_updates() ); Example return: Array ( [0] => stdClass Object ( [response] => latest [download] => [locale] => en_US [packages] => stdClass Object ( [full] => [no_content] => [new_bundled] => [partial] => ) [current] => 3.4.2 [php_version] => 5.2.4 [mysql_version] => 5.0 [new_bundled] => 3.2 [partial_version] => [dismissed] => ) )
stackexchange-wordpress
{ "answer_score": 7, "question_score": 3, "tags": "updates, core" }
Will activating a different theme preserve custom settings to current theme? I have theme A currently active, and theme A has custom settings (like header image, custom CSS, etc). I am having issues with theme A, and want to activate theme B while I troubleshoot these issues. If I activate theme B, and go to activate theme A later, will my custom settings be preserved?
Yes, your options should be preserved unless your themes are really bad and doing it wrong.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "themes, customization" }
Is there any way to not require email address or disable notification upon setting up a member? I'm setting up a website which will track the users by their role in relationship to the company. I want to use the built-in WP user functionality, but I don't want to send out notifications to all these people that I'm mucking around with the backend, when I have no intention of giving them edit access at all. I just want their information in there for the company's use. Specific Problems: Regardless of whether I use a plugin to extend WP's functionality or not, 1. Setting up a user requires an email address 2. The email address is required to be unique (I can't make my own test email address primary) 3. Setting up a user WILL generate an email notification I need to be able to either not require an email address, set up the users with the same corporate email address, or disable email notifications. Any help is appreciated.
Maybe the simplest way is to make a quick plugin that has your own form for inserting users. `wp_insert_user()` doesn't require an email address or password, and doesn't generate an email notification. function wpa70409_add_user(){ $userdata = array( 'user_login' => 'testuser', 'display_name' => 'Test User' ); wp_insert_user( $userdata ); }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "user registration" }
Get admin menu link Is there any way I can get the menu link for admins? < Similarly to the `edit_post_link()` that returns the edit link for loggedin Admins I would like to do something similar for the `edit menu` if there is anything like that?
You can use `admin_url('nav-menus.php');` This function can be used to get url's for any admin screen, please check out the codex for more information <
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "menus, admin, navigation" }
Display post details by post ID I need to display post details by ID on front page template (`front-page.php`). On the front page I want to display the post’s title, excerpt & featured image. I have tried to do that but no idea on how I should be doing that. Is there any function in WordPress that can be used to do it?
You can use `get_post` for that Example: <?php $post = get_post($id); //assuming $id has been initialized setup_postdata($post); // display the post here the_title(); the_excerpt(); the_post_thumbnail(); wp_reset_postdata(); ?>
stackexchange-wordpress
{ "answer_score": 6, "question_score": 0, "tags": "get posts, frontpage, post meta" }
get attributes/part of the gallery shortcode I'm trying to grab all image id's that are associated with the [gallery] shortcode that are listed as exclude. For example: if my post has `[gallery exclude="1,2,3"]` I'd like to get a variable that would echo like this `echo $excludes;` result `1,2,3` thank you for any help you can offer.
It took me a while to find a solution that worked for me, but since all I was looking for was the delimited list of attachment id's associated with a certain attribute like `exclude` or `hide`, this worked for me: # Grab the list of "hide" attribute $regex_pattern = get_shortcode_regex(); preg_match ('/'.$regex_pattern.'/s', $post->post_content, $regex_matches); if ($regex_matches[2] == 'gallery') : $attribureStr = str_replace (" ", "&", trim ($regex_matches[3])); $attribureStr = str_replace ('"', '', $attribureStr); // Parse the attributes $defaults = array ( 'hide' => '1', ); $attributes = wp_parse_args ($attribureStr, $defaults); if (isset ($attributes["hide"])) : $excludeID = get_post_thumbnail_id() . ',' . $attributes["hide"]; else : $excludeID = get_post_thumbnail_id(); endif; endif;
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "images, shortcode, gallery, regex" }
RSS feed - get specific item from external feed I am trying to figure out the best way to do this with Wordpress. I want to show a feed of news items on my site - the items are pulled from an external RSS feed. If an item is clicked, I want to show the contents of that specific item on a page within my own site. Looking at the contents of the external feed I am accessing, the unique identifier for each news item is stored in the query string of the link for that story, so I'm not really sure how I can use this to achieve what I want. Does anyone have any ideas at all? Thanks for any help
Displaying feeds usually links out of your site to the rest of the original content. You will have to use feeds that display all the content (or enough to show on your own pages) and then pass that information to a page using a template that can receive and display it. An alternative is to just pass some unique identifyer to your 'content' page and then filter the feed to just show the item matching the identifyer i.e. link url would be unique. - this is all considering leaving the original content where it is: you can automatically post RSS content to your own site using a plugin like feedwordpress. This will syndicate and allow many options to display the content. Its probably the best option.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "rss, feed" }
what is the best and safest way to allow users to register to site I'm wanting to allow users to register to my wordpress site. What is the best and safest way to implement this? The ultimate goal is to give the users the option to subscribe to alerts when updates are made to the site. Thanks,
The easiest way is to make sure you have the following settings under `Settings > General`. Under the **Membership** settings make sure `Anyone can register` is checked and `New User Default Role` is set to subscriber. This will allow people to register at `example.com/wp-login.php?action=register` You can also use plugins like theme my login or Gravity Forms User registration (and I'm sure others) to make the sign up pages/process simpler. I guess I'd have to know more about why you want to allow subscribers. If you wanted an even more limited role then subscibers provides you could create a new role via role scoper or the members plugin and assign that to new users. However, if your goal is just to give users updates why not just provide them updates via email. There are a ton of plugins that do this. Automattic has one via jetpack or Subscribe2 is also an easy way to do this.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "login, user registration" }
Exclude posts based on an array I'm using a custom meta box to output a list of post IDs within a particular post type ("Publications" in this example). Is there a way I can output this array into a custom loop to only show posts with those ID's? This is the code I am using; Meta box array $related = get_post_meta( get_the_ID(), 'ps_related-publications', false ); foreach ( $related as $meta ); WP_Query loop $related_publication_widget = new WP_Query( array ( 'post_type' => 'publications', 'p' => $meta, 'posts_per_page' => '-1', ));while ( $related_publication_widget->have_posts() ) : $related_publication_widget->the_post(); Because the ID's are output as just numbers (Ie; without the ',' required to separate ID's in a query, it's only showing the latest post as oppose to all of them as defined in the loop. Any ideas?
You're looking for `post__in` & `post__not_in` parameters < Both of them are an array of ID's for the post's to include or exclude in the results BTW in your code, you had a semicolon just after your foreach
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "loop, metabox, query, array" }
Disable pasting of images into wordpress editor I have a user who loves to do this, It works fine for the website, but when it gets transferred over to the newsletter it breaks the newsletter. Is it possible to disable pasting of images into the WordPress editor without removing the visual editor?
You can hook into TinyMCE's paste function and filter user actions using javascript. So yes it is possible. <
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "visual editor" }
Rewrite URL for taxonomy listing I have created several custom taxonomies and each "archive" can be viewed on the url mysite.com/taxonomy/term Is it possible to rewrite the URLs so my taxonomy archive lives under for example mysite.com/calendar/taxonomy/term instead?
When creating a custom post type you can define the slug using the argument "rewrite" < or you could use a plugin <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "custom taxonomy, url rewriting" }
Can index.php take over for front-page.php in template hierarchy on second page? I'm confused by the template hierarchy in WordPress. I have `front-page.php` in a theme I'm developing. It looks great and it works, but then when a user clicks 'Older Posts', it just shows the same content as before, but the URL is changed to ?paged=2. Looking at the diagram about Template Hierarchy on Wordpress Codex, since the second page is _not_ the front page, I'd expect it to fall through `front-page.php` to either `home.php` or `index.php`, but it's not doing that; it's just loading `front-page.php` over and over again. So how can I load, say `index.php`, for every page other than the front page? And also, am I crazy for expecting what I expect? The second question might be subjective. Please only answer the first if you think I am crazy.
Pagination does not affect the template usually, `paged.php` is the exception but not of interest for your question. To style the first page differently than later pages check for if ( is_front_page() and 1 < get_query_var( 'paged' ) ) { // code for later pages }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "templates, pagination, frontpage" }
How Do I Programmatically Better Organize Custom Post Type Menus? A project I inherited had a dozen custom post types. Trouble is, they all come off the admin menu sidebar separately. It's not very tidy. Is there a plugin where I can make these subitems of a parent menu, or is there a way, programmatically, I can edit my theme's functions.php to make it make these as submenus?
On the function to register a new custom post type can you set this CPT as Submenu to a exist menu item. Use the param `show_in_menu` A example: register_post_type( 'issue', apply_filters( 'wpit_register_issue_post_type', array( 'labels' => $issue_labels, 'rewrite' => $issue_rewrite, 'supports' => $issue_supports, 'taxonomies' => $issue_taxonomies, 'menu_position' => 5, 'public' => TRUE, 'show_ui' => TRUE, 'show_in_menu' => 'edit.php', 'can_export' => TRUE, 'capability_type' => 'post', 'query_var' => TRUE ) ) ); You find the string for the items on mouse over, like `upload.php`on the item _Media_.
stackexchange-wordpress
{ "answer_score": 7, "question_score": 3, "tags": "custom post types, admin menu, sub menu" }
Change the menu home link to something else I'm using the built in menu system, and I wan't to change the text of the home menu link to something else, like "hjem", and i have tried placing this in the code: <?php wp_page_menu( array( 'show_home' => 'Hjem', 'sort_column' => 'menu_order' ) ); ?> But that did nothing but show the menu, with the home menu text "Home". What do I do?
Funnily enough, I see the same behavior in WordPress 3.4.2 and 3.5-beta2. No plugins active, theme TwentyEleven. _**Even setting_** `show_home` as `false` will show the _Home_ button ?! Checking the core, I see this filter that does the trick: add_filter( 'wp_page_menu_args', 'wpse_70551_change_page_menu'); function wpse_70551_change_page_menu($args) { $args['show_home'] = "Hjem"; return $args; } **[Update]** This was a bug with the Bundled Themes. > The culprit is `twentyeleven_page_menu_args()` (`twentytwelve_page_menu_args()` in Twenty Twelve). > > It ignores any passed value and enforces true instead: < > > 22331.patch​ is a fix for all three themes.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "menus, homepage" }
Adding a class to post title considering the title length I searched for "title length" in questions but results were all about setting max length and limiting and.. What I want to do is to create an if-statement, to determine if the post title has more than 68 characters or not and if it had, add `smaller` class to it. I wrote the code like this: <?php $permaLength = strlen(the_title()); ?> <h2 class="<?php if ($permaLength > 68) {echo 'smaller';} ?>"> <a href="<?php the_permalink() ?>"> <?php the_title(); ?> </a> </h2> but it seems that `the_title()` function is not returning the value and instead it's echoing out. Is there an alternative way to fetch the title length?
`the_title()` echoes the result. Use `get_the_title()` to return the title.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "title" }
Display Meta Data with HTML? Is it possible to display the custom field/meta data content with some html? Usually i would use the following to just display the content... <?php echo get_post_meta($post->ID, '_cmb__description',true);?> However, when there is actually meta content i want it to appear within some html, but i only want that html to appear when there is meta data to appear? <?php echo get_post_meta($post->ID,<div class="box">. '_cmb__description'. </div>,true);?> Is this possible? I'm not that up to scratch with it all, so wasn't sure if it was doable at all.
Yes, just check if you got something back from the post meta: $value = get_post_meta($post->ID, '_cmb__description',true); if ( $value ) echo "<div class='box'>$value</div>";
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom field, post meta" }
Custom post type & role issues I am having issues with using custom post types and custom user roles. I created a custom post type called Businesses. Then I created capabilities for users of a certain type to be able to add and edit business listings. The problem I am having is when I create the user type and add the capabilities of edit_business, edit_businesses, read_business, publish_businesses, the user has the ability to edit other peoples businesses. I can't figure out why this is happening. A snippet of the code I used to create the capabilities is `'capabilities' => array( 'edit_post' => 'edit_business', 'edit_posts' => 'edit_business', 'edit_others_posts' => 'edit_others_businesses', 'publish_posts' => 'publish_businesses', 'read_post' => 'read_business', 'read_private_posts' => 'read_private_businesses', 'delete_post' => 'delete_business' )` Any help understanding this would be appreciated
So I figured out the problem here. When you use the members plugin and create roles for custom post types you need to create a function which maps out your meta capabilities. <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom post types, capabilities, user roles" }
Displaying custom post type on front page I added a new custom post type to my Wordpress theme but it refuses to show on the homepage. I tried setting <?php query_posts( array( 'post_type' => array('post', 'reviews') ) );?> but it doesn't seem to work, it just loops my normal posts. Any suggestions would be greatly helpful. Here's a pastie of my index if anyone wants to see it: <
I would avoid the use of query_posts -- it forces another database hit. There are plenty of other ways to hook in and change the query before posts are fetches. `pre_get_posts` is one of them. To display multiple post types on the home page (pages and posts in this example): <?php add_action('pre_get_posts', 'wpse70606_pre_posts'); /** * Change that query! No need to return anything $q is an object passed by * reference {@link * * @param WP_Query $q The query object. * @return void */ function wpse70606_pre_posts($q) { // bail if it's the admin, not the main query or isn't the (posts) page. if(is_admin() || !$q->is_main_query() || !is_home()) return; // whatever type(s) you want. $q->set('post_type', array('post', 'page')); } This would go in your themes's `functions.php` file or in a plugin.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "custom post types, php, homepage" }
Display all posts in current category I am looking to create a behavior as shown in the following link: < Here all posts from the same category are being displayed. Currently, it is handwritten HTML code, I want to mimic this behavior using PHP code in my single.php. !posts Following is the code I have written so far <?php $category = get_the_category(); <ul> query_posts('cat='.$category); if ( have_posts() ) : while ( have_posts() ) : the_post(); <li><a href="get_permalink( $id );">the_title();</a></li> endwhile; endif; </ul> <br/> ?> Can someone help in making it work?
Try this: $cat = get_query_var('cat'); $PozCat = get_category ($cat); $PozCat->id // give to us current cat id. Then use this hook in your query: <ul> <?php $cat = get_query_var('cat'); $PozCat = get_category ($cat); //$PozCat->id query_posts('posts_per_page=-1&cat='.$PozCat->id); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <li><a href="<?php the_permalink();?>"><?php the_title(); ?></a></li> <?php endwhile; endif; ?> </ul>
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "php, categories" }
Change a url / link if a user is logged in? I'm working on some themes for a multisite and would like to modify the code below. It relates to a special div that will display an image or logo that users upload. Normally the logo links to the home page of the blog, but could it be modified so that if the user is logged in it will link to "/themes.php?page=wptuts-settings" instead which is the logo upload screen? Thanks <div class="art-headerobject"><div class="mylogo"> <?php $wptuts_options = get_option('theme_wptuts_options'); ?> <?php if ( $wptuts_options['logo'] != '' ): ?> <a href="<?php echo get_option('home'); ?>/"><div id="logo"> <img src="<?php echo $wptuts_options['logo']; ?>" /> </div> <?php endif; ?></div></a></div>
Change the line with the URL: <a href="<?php echo get_option('home'); ?>/"><div id="logo"> … and check if the user is logged in: <a href="<?php if ( is_user_logged_in() ) { echo admin_url( '/themes.php?page=wptuts-settings' ); } else { echo home_url( '/' ); } ?>/"><div id="logo"> And `echo get_option('home');` is not correct. See `wp-includes/link-template.php:home_url()` to understand why the real home URL is a little bit more complex.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "conditional content" }
Show default content if custom WP_Query has no posts I have a custom loop to show posts that meet a certain set of $args like this: <?php $recent = new WP_Query( $orderargs ); while($recent->have_posts()) : $recent->the_post();?> This works great when the $orderargs bring up posts, but in some situations, there will be no posts, and I want to show some default content then. So what do I add to this / how do I restructure this so that if the query has no posts, display default content instead. Thank you, Ian
You do that the same way like with regular posts: if ( $recent->have_posts() ) { while($recent->have_posts()) { $recent->the_post(); // print posts } } else { print 'no posts found'; }
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "wp query, loop, customization" }
What does this error mean? WordPress database error: [MySQL server has gone away] WordPress database error: [MySQL server has gone away] I did not make any changes, and the host says that there is no problem with MySQL. Can anyone explain what the error means? and how to troubleshoot? This is a shared hosting environment, and no recent changes where made to the site. Also other wordpress sites are encountering the issue with this same shared server.
This is not a WordPress error, it is from MySQL: > The most common reason for the MySQL server has gone away error is that the server timed out and closed the connection. Talk with your host again.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "errors" }
How to check if I am in admin-ajax.php? Right now for my plugin, I am using `in_admin()` to determine if the user is in the frontend of the site or in the admin area. However, the problem occurs when plugins use `admin-ajax.php` to process ajax requests. I need a way to register hooks and plugins only when processing `admin-ajax.php` file or in the frontend of the site. What is the best way to go about doing that?
Check the constant `DOING_AJAX`. Its definition is the first working code in `wp-admin/admin-ajax.php`. Some very weird plugins, like Jetpack, are defining that constant in unexpected places, so you might include a check for `is_admin()` as well. Example: if ( is_admin() && defined( 'DOING_AJAX' ) && DOING_AJAX ) { // do something } I have asked for a simpler way to check this a long time ago, and this was finally implemented in 4.7.0. So for WP 4.7 and higher you can use: if ( wp_doing_ajax() ) { // do something }
stackexchange-wordpress
{ "answer_score": 72, "question_score": 35, "tags": "ajax" }
Certain aspects of site suddenly not working in Chrome and Firefox My site has been working perfectly in all browsers, until suddenly 2 days ago. Now in Chrome and Firefox, the main page accordion slider is stuck, the "log in" button is not functional, and a few other things. I have tried the site in Safari, Opera, Internet explorer and it still looks and operates as it should. I have cleared the cache and cookies in Chrome and Firefox multiple times hoping that was the problem, but it still appears broken. I even have switched and re-uploaded the theme, same deal. Also, I'm pretty sure it's not a plugin conflict, I have only installed one new plugin and it was days before this happened, and I have since deleted it. I also tried changing the DOCTYPE. Anyone have an idea of what has gone wrong? The site is www.fearlessblue.com (excuse the site, it's my first, and I'm definitely a noob). All the pages are locked for development, so that is not my concern)
It looks like a javascript error is preventing scripts from running. There error is from the script cloudflare.min.js, so perhaps it has to do with how you have Cloud Flare setup? Did you just recently start using it? In particular it seems to want to load a non-existent image from '
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "css, debug" }
Site URL always in front of other URLs My Wordpress site is having a bad URL structure when I'm adding new URL. For example in comments, when commentators fill in their website, it always has this structure ` The same thing happens in my side bar widget. When I add new text widget and put something like this `<a href="facebook.com/mypage" title="Find Us On Facebook"><span class="social">Find Us on Facebook</span></a>`, the result showing this instead ` Could anyone help me solve this please!
You need to start your links with ` Examples: 1. The link `facebook.com/mypage` becomes ` 2. The link `www.commentorsite.com/` becomes ` This will stop the links becoming ` or `
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "urls" }
I need help in designing a custom post type I've been sitting on this for three days and I still haven't figured out a good way to solve this problem—that's why i want to ask a community about it. I'm creating a page, which will have some historical routes in my city. I therefor need to create a custom post-type, which will be the route. Route have points. Each point store multiple data: name, content, GPS-coordinates, author, etc. So I need to create a repeatable area called `point` and there I'll insert all the data I need (amount of points is dynamic so this area need to be repeatable). I've done that with help from this question: Create more Meta Boxes as needed It works fine, but there's a problem because the content-field needs to be the TinyMCE-editor and for now I'm stuck on the part where i add a repeatable area through jQuery, because I can't add TinyMCE to it in a easy way. Is this a good plan or should I try another solution?
If Points have such a complex structure then shouldn't you think of it as another custom post type, and associate them to a Route (or to several Routes)? that way you could have a Point in different Routes, which could be a reasonable expectation.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types" }
Decrease file size upload in Media By default, I have a 2m limit of uploads. I want to decrease this number. I found out that this code: function custom_file_max_upload_size( $file ) { $size = $file['size']; if ( $size > 1000 * 1024 ) { $file['error'] = __( 'ERROR: you cannot upload files larger than 1M', 'textdomain' ); } return $file; } add_filter ( 'wp_handle_upload_prefilter', 'custom_file_max_upload_size', 10, 1 ); works by adding to functions. However, it does not update the upload size information when the user is on upload screen. It still displays `Maximum upload file size: 2MB`. How can I change that text to 1mb? Or alternatively, a different approach to decrease the file size (that does **not** include editing php.ini or htaccess...)
That number is taken from `wp_max_upload_size()`, and there is a filter: `'upload_size_limit'`. See `wp-admin/includes/template.php`. So this should work (not tested): add_filter( 'upload_size_limit', 'wpse_70754_change_upload_size' ); function wpse_70754_change_upload_size() { return 1000 * 1024; }
stackexchange-wordpress
{ "answer_score": 7, "question_score": 7, "tags": "php, uploads, media, limit" }
How do I separate author avatars and comments in 3.4.2? I see plenty of tutorials for much older versions of WP online, but cannot find one for 3.4.2 to separate comment content and the author's avatar/gravatar. I'm seeking a code that separates the actual comments content from the gravatar **and does so in the simplest way possible** , I'd rather not update comments.php every time there's an update to the WP core. Is there a simple way to do this with wp_list_comments? I'm doing this for design purposes. This is how I currently call avatars: <?php wp_list_comments('avatar_size=60'); ?>
Ok, so this is what I've done. If anybody has a better idea I will leave the answer open for a few hours and choose it! <?php if($comments) : ?> <ol> <?php foreach($comments as $comment) : ?> <li id="comment-<?php comment_ID(); ?>"> <?php if ($comment->comment_approved == '0') : ?> <p>Your comment is awaiting approval</p> <?php endif; ?> <cite class="fn"><?php comment_author_link(); ?> on <?php comment_date(); ?> at <?php comment_time(); ?></cite> <?php comment_text(); ?> </li> <?php endforeach; ?> </ol> <?php else : ?> <p>No comments yet</p> <?php endif; ?>
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "comments" }
Make theme editor to show all theme's files Is there a way to make all files (also in subfolder) in my theme directory visible in the theme editor? I need a way to edit themes without having to upload a new one every time. Thanks!
I think, this is not possible in the current version, is a old ticket in the trac. But you can add a other editor via plugin and it works, like WPide
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "theme development, directory" }
How to Translate Contact Form 7 using qTranslate? I'm using Contact Form 7 for my forms and also qTranslate to translate my website. I would like to translate all my fields and for that I used: <!--:en-->First Name (required)<!--:--><!--:ru-->Фамилия (обязательно)<!--:--> But it display this: First Name (required)Фамилия (обязательно) What should I use to make it work?
What I normally do when using this combination of plugins is to create _one form_ per language. Easy and effective. You could also try qTranslate quicktags: `[:en]English text[:ru]Фамилия`. But much probably this will lead to some issues down the road.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 3, "tags": "translation, plugin contact form 7, plugin qtranslate" }
Scheduled posts: set default time? I want to be able to set the default time in the options for a Scheduled Post to be a specific time of the day, as opposed to it defaulting to the current time. Is there a plugin or some code I can add/tweak to accomplish this? I was unable to find anything here or on Google to do this.
The plugin Automatic Post Date Filler suggested in the comments is a perfect solution. Even better than imagined with all the various preferences to how it dynamically sets up the defaults when you edit the scheduled time.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 3, "tags": "scheduled posts" }
Limit the number of posts a category can have - newest post goes in, oldest one drops out, possible? plugin? I would like to limit the number of posts which can belong to a given category, for example: The "News" category should have no more than ten posts. When the eleventh post is created the oldest post should be dropped from the category without the need to edit the post manually to remove it from the given category. Does it sound possible?
1. Hook into `publish_post`. 2. Check if the post is in the category `news`. 3. Get all posts with that category: $query = new WP_Query( array( 'category_name' => 'news', 'posts_per_page' => -1 ) ); 4. Update the category of the oldest post if necessary: `wp_set_post_terms()`.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "posts, categories" }
Free themes for commercial use Does anyone here know weather or not a free theme on Wordpress can be used for commercial purposes? I am using the Pinboard theme. Would I need to get some sort of licence to operate the website as a business?
The Pinboard theme is in the WordPress theme repository and released under the GPL license, this means that you are free to use and redistribute the theme code. The GPL license gives you.... * the freedom to use the software for any purpose, * the freedom to change the software to suit your needs, * the freedom to share the software with your friends and neighbors, and the freedom to share the changes you make. More here: <
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "themes, licensing" }
How to display non-page / post content I have a custom made Twitter stream on my site. I want to have a permalink for each tweet which would go to a page which would display only the tweet - no other content - surrounded by my custom theme. Ideally I would get Wordpress to display a Page Template on a certain url (something like /tweet/<tweet_id>), but I don't want to create a Page because it will appear in the main menu. I'm happy to write a plugin but my Google-fu is failing help me to figure out how to display just that plugin's content on a page.
I decided to use a Page and looked at how Exclude Pages hides them. This is what I came up with (in `functions.php`): add_filter('get_pages','mytheme_exclude_pages'); function mytheme_exclude_pages ($pages) { $showPages = array(); foreach ($pages as $page) { if (!in_array($page->post_name, array('no-show', 'shy-page'))) { $showPages[] = $page; } } return $showPages; }
stackexchange-wordpress
{ "answer_score": 0, "question_score": 2, "tags": "plugin development, page template, routing" }
Restrict certain posts from being sent to the feed subscribers Is there any way to restrict certain category’s posts or certain posts from being displayed into site default feed after published? I’m asking this because I don’t want few specific categorie’s posts to be sent to my feedburner subscribers. I think preventing them from displaying into site feed will also prevent them to be sent to the the feed subscribers! What do you think? Or is there any way to do so..
Simple answer is yes you can. :) First check out Wordpress's codex here on their RSS feeds. < Then what you can do is change the default head rss links that let browsers know that there is an RSS feed. In your theme find: <link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="<?php bloginfo ('rss2_url');?>" /> And replace the `href="<?php bloginfo ('rss2_url'); ?>"` with an alternate rss feed link as explained in the WordPress Codex. You will want to do it also for the Atom Feed and the regular rss feed as well which are right below the first link i posted above.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "feed, user access, content restriction" }
Count & Display Database Queries I'm looking for an solution how I can count and display all queries in a WordPress site. Does anybody know, if there is an good plugin? Otherwise it would be an solution to check the queries on the console, because I'm working a lot with the console.
You can paste this block of code in your currently active WordPress theme `functions.php` file: function wpse_footer_db_queries(){ echo '<!-- '.get_num_queries().' queries in '.timer_stop(0).' seconds. -->'.PHP_EOL; } add_action('wp_footer', 'wpse_footer_db_queries'); The above block of code, will render an HTML comment in the footer of your theme (before `</body>` and `</html>`, containing the number of database queries and how log they took to retrieve.
stackexchange-wordpress
{ "answer_score": 10, "question_score": 9, "tags": "database, query, hooks, debug, count" }
Which filter/action hook gets triggered after a query has been performed? Is there an action or filter that gets called after an instance of WP_Query performs a query?
Yes there is, `the_posts` gets called just after the posts have been selected from the database and it passes an array of `$posts` as a first parameter and the `$wp_query` object as second parameter to your hooked function.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 2, "tags": "wp query, filters, actions" }
Show latest posts on responsive theme I've installed Responsive theme on my new blog. I want the home page to show my recent posts, so I configured `Settings->Reading` to show my 10 recent posts, instead of a static page. Alas, the static home page (with the "Call to Action button") remained. Any idea how to change it?
Yes and you can find out more on our support forum as well. Thanks for using Responsive, Emil
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "homepage, recent posts, responsive" }
How to change image's author via a function when using GravityForms uploader? I am wondering if there is a way to manually change the author of images. I am using Gravity Forms which sets the post author to the current user but does not set them as the author of the images they upload. I figure there might be a way to add a function which finds the current user and then sets the author of the images they upload to that user.
add_action("gform_user_registered", "image_author", 10, 4); function image_author($user_id, $config, $entry, $user_pass) { $post_id = $entry["post_id"]; $args = array( 'post_parent' => $post_id, 'post_type' => 'attachment', 'post_mime_type' => 'image' ); $attachments = get_posts($args); if($attachments) : foreach ($attachments as $attachment) : setup_postdata($attachment); $the_post = array(); $the_post['ID'] = $attachment->ID; $the_post['post_author'] = $user_id; wp_update_post( $the_post ); endforeach; endif; }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "images, uploads, author, plugin gravity forms" }
Adding if statement to content for homepage I have an if statement already in my loop to display content based on post type. I was wondering if there was a way that I could say to ignore that section if it is the front page/homepage. Here's a sample of my code: <?php if( get_post_type() == 'reviews' ) { ?> <div class="post-review"> <div class="review-score"> other div stuff </div> <?php } ?>
Check for `is_front_page()` and if you want to catch the first page only inspect `get_query_var( 'paged' )` too: if ( is_front_page() and 2 > get_query_var( 'paged' ) ) { // we are on the first page of the front page }
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "php, loop, homepage" }
How can i limit the character length in excerpt? > **Possible Duplicate:** > excerpt in characters I have a question after reading this post (How to highlight search terms without plugin). I like this function(Search Term Without Plugin) very much but the character length is too long. What php code should i add to make the excerpt shorter? Would appreciate if someone can suggest it. Thank you!
add these lines in function.php file function custom_excerpt_length( $length ) { return 20; } add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
stackexchange-wordpress
{ "answer_score": 21, "question_score": 12, "tags": "excerpt" }
Twenty Eleven header resize I seem to have a problem customizing the Twenty Eleven theme. I would like that the top header above the header image to have a background color that goes from side to side in the window. Found out that the problem may come from max-width set to 1000px, but could not find where to put it so it doesn't mess up the theme elsewhere. How can I achieve to have a color on the top of the page (ex. like facebook top blue header) that has the width of the browser?
In your Twenty Eleven child theme (don’t edit the main theme!) create a new `header.php` file, copy the content from the parent theme, and replace this part: <body <?php body_class(); ?>> <div id="page" class="hfeed"> … with something like this: <body <?php body_class(); ?>> <div style="background:#345;color:#eee;padding:10px 20px;margin:0 -2em">Hello</div> <div id="page" class="hfeed"> But move the CSS into a copy of the `style.css`, and adjust the styles in the media queries too, because `body` doesn’t have a `padding` in smaller windows, and you have to remove the negative `margin` then.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "theme twenty eleven" }
Exclude posts by post meta value I have constructed this query to sort posts on the home page by a set position number in a custom field. However, I need to be able to exclude posts with the position set to '0'. Below is the code working to sort the items, but I cannot get anything to work with excluding the posts. <?php query_posts('meta_key=home_post_id&orderby=meta_value_num&order=DESC'); ?>
$args = array( 'meta_key' => 'home_post_id', 'orderby' => 'meta_value_num', 'order' => 'DESC', 'meta_query' => array( array( 'key' => 'home_post_id', 'value' => 0, 'compare' => '>', 'type' => 'numeric', ) ) ); query_posts($args); Something like this should work but I haven't tested it .) Let me know if it works.. Reference: WP_Query - Custom Field Parameters
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "query posts, query, post meta, exclude" }
Custom GET Parameters In Plugin's Admin Page In my plugin's options page, I'd like to have custom GET parameters. WordPress already has a `?page=<slug>` GET parameter, so simply linking to something like `?myparameter=value` won't work. I though of reading the `page` parameter, and then linking to something like: `?page=<slug>&myparameter=value`. This seems workable, but I don't know if its the best practice. The complexity of my plugin really doesn't warrant sub-pages for now. So is this the best practice or am I missing something?
I'd recommend using `add_query_arg()`: $url = add_query_arg(array( 'foo'=>'bar', 'custom'=>'var', 'page'=>'myadminpage' ), admin_url('admin.php')); The second argument, `admin_url('admin.php')`, is optional - and if omitted it uses the url of the current page you are on.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "plugin development" }
Redirect from ip to domain I want to prevent site to be accessible by ip. It could be accessible by only domain name, so I tried with htaccess trick. RewriteCond %{HTTP_HOST} !^mydomain\.com [NC] RewriteRule .? [R=301,L] It did the trick now my siteurl is changed to mydomain.com instead of my ip. But as per my knowledge its not complete solution. Whenever I change permalinks new htaccess will be generated so above condition will be removed. So I thought I have to try in index.php, tried to redirect if ip is there in url by following: if(strpos($_SERVER['HTTP_HOST'],'111.111.111.11') !== false) { header("Location: mydomain.com".$_SERVER['REQUEST_URI']); } but it did nothing still site accessed by ip. Let me know if my approach is right or not. Suggest me anything else if there.
WordPress does not create a complete new .htaccess. It just rebuilds the part between the WordPress markers: # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L] RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress Any rule placed outside of this block will not be touched.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "redirect, htaccess" }
Contact Form 7: Redirecting on a condition? I am doing a survey using the plugin "Contact Form 7". I want to insert an acceptance box. ONLY if people check this box and click "submit", they should be redirected to another page, where I am going to ask for their e-Mail-addresses. If they don't check "acceptance" there should be no redirecting. How can I do this? I ready inserted on_sent_ok: "location = "" - BUT: This ignores if the acceptance box is check or not.
I found an answer myself: Redirecting without a condition When you use the Wordpress plugin “Contact Form 7” you can redirect the user to another page after submitting the answers by the follwing code: on_sent_ok: "location.replace(' The line of code you have to copy into the “settings” box at the end of a specific form you created. Redirecting on a condition If you want to make the redirecting depending on a specific answer, you can use the following code: on_sent_ok: " if (document.getElementById('car').value=='yes') {location.replace(' else { location.replace(' } " The code in bold letters has to be changed by your settings. For example: The question with the id “car” has two possible answers: “Yes” or “No”. If a person selects “Yes” he or she should be redirected to “ If “No” is selected, the user should be redirected to “
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "redirect, plugin contact form 7" }