INSTRUCTION
stringlengths
11
999
RESPONSE
stringlengths
0
999
SOURCE
stringlengths
16
38
METADATA
dict
Yoast SEO plugin - Sitemap links greyed out & page priority I have a sitemap - < Why are some of the links within the sitemap greyed out? Also is it worth changing the priority of some of the pages to achieve better seo results?
Grey links are how it styles visited ones. Priority is mostly for indexing purposes (as is rest of sitemap), I highly doubt is has any impact on search engine ranking.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "seo, plugin wp seo yoast" }
Changes in code only show after changing theme I have a weird problem that happens only in one of my Wordpress sites (which is on a development server with many other wordpress sites that don't have this problem): When I make changes in code - be it php, css or html - I can't just go to my site and refresh the pages for the changes to show up. I have to go to the themes page in the admin area, change to a different theme, then change back to the original theme, and only then can I refresh the page and see that changes I made. Could it be a server configuration, something to do with caching? Or is it a plugin that might be causing the problem? P.S I don't even know how to tag this question. Any help will be appreciated.
In the end we disabled all plugins, then turned them on again, and miraculously - the problem disappeared :)
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "code" }
Check if user is logged in, inside php file in template directory I have a php file in my template directory which generates some data from a database. I only want this data to be accessable for my wordpress users. I tried by using this line of code but it gives me an error saying "headers already sent". What is wrong? Or is there any other way to solve this? <?php require_once('../../../wp-blog-header.php'); if (is_user_logged_in()) { echo "hello world"; } else { echo "You do not have access to this resource!"; } ?>
Since the file is in your theme directory, Wordpress may not want the user to "directly" access it. Why not create a Page in wordpress, assign a Template Name to your PHP page and then assign that to the new page created in wordpress. For example, you would have a new page called "Members Only" and its template is "php-page-located-in-theme". Then, in the code, you don't have to call the blog header, just simply wrap the entire page in your "Is user logged in" if else statement. Example: <?php Template Name: php-page-located-in-theme get_header(); if ( is_user_logged_in() ) { echo 'Welcome, registered user!'; /*PHP Generated Content Goes Here*/ } else { echo 'You cannot access this page.'; } get_sidebar(); get_footer(); ?>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "authentication" }
Add multiple images to author profile page I'm developing a directory style theme using multi-site and each new author needs to be able to upload 5-10 photos to be displayed in their profile page. Is there any way of doing this? I don't mind if it's a plugin as this theme is for a client and not for general release.
You can use this for an author photo: < And this one might give you multiple images for the author: < The final approach is to use a gallery plugin of some kind (NexGen Gallery Perhapse?) and create an album for each author, labeling it "John Doe". Then, call the gallery in the authors.php file and have it get the proper gallery.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "images, dashboard, profiles" }
where to split off footer.php Is there any particular reason why index.php in most templates usually seems to go all the way from just after the start of #main to right before it's closing tag, with that closing tag contained in footer.php. In my theme it would be handy to have #main's closing tag in the index/single/page files not in footer.php ( so the split would be another couple of lines down the code from where i normally see it ). And if there's no real difference then should i also move the header/index split up a line to get the #main div start tag into the index/single/page etc files ?
It's a personal choice. If the containing markup is consistent across all templates it doesn't matter if they're in the template or header/footer, it's just one less bit of markup that gets repeated in every template.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "theme development" }
WP_query 'orderby=none' Problem I have another database which stores post's IDs and I want do display them using WP_query to use the WP default pagination. I'm using _orderby => none_ to preserve the original order, but the result reorders them by IDs. $ids = array (60, 23, 78, 46, 105, 130) $args = array ( 'posts_per_page' => -1, 'post__in' => $ids, 'orderby' => 'none' ); $query = new WP_Query ( $args ); while ( have_posts() ) : the_post(); echo '<li>'; the_title(); echo '</li>'; endwhile; Could anyone help me? Thanks, Romulo De Lazzari
You can order them manually after the query is complete: $ids = array (60, 23, 78, 46, 105, 130) $args = array ( 'posts_per_page' => -1, 'post__in' => $ids, 'orderby' => 'none' ); $query = new WP_Query ( $args ); $ordered_posts = array(); foreach($ids as $rpid) foreach($query->posts as $index => $fpid) if($fpid->ID === $rpid) $ordered_posts[] = $query->posts[$index]; $query->posts = $ordered_posts; while ($query->have_posts() ) : $query->the_post(); echo '<li>'; the_title(); echo '</li>'; endwhile; And like Mamaduka posted, if it's a custom loop use the $query methods instead of the global functions...
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "wp query, order" }
What makes WP so SEO friendly? I keep hearing that Wordpress is the best SEO solution, better than most static websites because of multiple reasons. I then go on to hear contradicting information elsewhere. So: Is Wordpress generally more SEO friendly/ready then most static html websites? What makes it more SEO friendly? Can I take any SEO tips from a Wordpress installation to improve a static HTML page SEO?
When you hear about SEO-friendliness of CMS it is essentially same as for static page - how URL looks and what gets into source of page. Essentially WP is considered SEO-friendly because: 1. It is easy to get pretty permalinks enabled and working 2. There is large choice of themes and plugins, aimed at following recommended SEO guidelines (titles, meta tags, structure of headings, etc). So this is not about WP being somehow unique. It is about it having tools (both native and extensions) to follow good practices for on-page SEO.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "seo, google search, search engines" }
How to have a custom URL structure for a custom post type? Even though this question sounds like others here is my problem: The site I am updating **had** a permalink structure of `/%postname%`, during this time I created a custom post type of "popups" (rewrite slug = 'popups') so the urls were: /popups/the-post-name **Now** the site has a blog, and the permalink structure has been changed to `/blog/%postname%`, this changed the custom post type url structure to: /blog/popups/the-post-name I want to keep the blog permalink structure as `/blog/%postname%` but I want to have a custom url structure for my custom post type that is not tied to the blog permalink. So instead of the urls for my custom post type of popups showing up as: /blog/popups/the-post-name I want it to show up as: /popups/the-post-name while retaining the blog permalink of `/blog/%postname%`
When you registered the post type, one of the arguments was rewrite, which took an array. make sure there's a `with_front` argument in the `rewrite` array, and set it to `false`. <?php $args = array( // other stuf... 'rewrite' => array( 'slug' => 'popups', 'with_front' => false ), // other stuf... ); register_post_type( 'type', $args ); That should take care of it. **Important:** Be sure to flush your rewrite rules after changing the code (go to settings > permalinks and hit save).
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "custom post types, url rewriting, urls" }
Deactivate plugin upon deactivation of another plugin Wondering if its possible to deactivate a plugin in the deactivation code of another plugin? IE. i have a widget that i'm adding via its own plugin that won't function if the 'master' plugin isn't activated...
Yes, register a deactivation hook in your first plugin, and inside this hook deactivate the 2nd plugin using the `deactivate_plugins()` function
stackexchange-wordpress
{ "answer_score": 1, "question_score": 3, "tags": "plugins, deactivation" }
Is there a way to send HTML formatted emails with WordPress' wp_mail() function? Is there an action_hook or something similar that could help me achieve this? I tried adding markup in a PHP string variable and just fired off an email with the `wp_mail()` function like so: $email_to = '[email protected]'; $email_subject = 'Email subject'; $email_body = "<html><body><h1>Hello World!</h1></body></html>"; $send_mail = wp_mail($email_to, $email_subject, $email_body); But it showed up as plain text? Any ideas?
from wp_mail codex page: > The default content type is 'text/plain' which does not allow using HTML. However, you can set the content type of the email by using the 'wp_mail_content_type' filter. // In theme's functions.php or plug-in code: function wpse27856_set_content_type(){ return "text/html"; } add_filter( 'wp_mail_content_type','wpse27856_set_content_type' );
stackexchange-wordpress
{ "answer_score": 79, "question_score": 70, "tags": "hooks, wp mail, html email" }
Wordpress permalink, stop redirection I'm having some hard-time with with WordPress permalinks. WordPress 3.1 seems to force url redirection, ex: This is the correct post url: If I go to any of the url's below WordPress is redirecting me to the url above or Basically, what I want to achieve is that WordPress matches the post id, in this case 1, and presents the post content without redirecting users to the correct url. Any ideas on how to achieve this ? Thank you all! PS- Please don't move this question to SO WordPress because I've already tried to get an answer there for a couple of days without luck.
First, I'll say it's beyond me why you'd want to do this, I really don't think it's a good idea, but in any case... If you look in `/wp-includes/canonical.php`, you'll see how WP is fighting you on this. The only way I'm aware of to get around it is to go looking for the post yourself based on the post id query var (which should be set and hopefully correct) and resetting the `$wp_query` global to whatever is found, then manually setting the status header so a 404 isn't sent to the browser. function wpse27871_404_fakeout() { global $wp_query; if( $wp_query->is_404 && get_query_var('p') ): $this_query = new WP_Query( 'p='.get_query_var('p') ); if( $this_query->post_count !== 0 ): $wp_query = $this_query; status_header(200); endif; endif; } add_action('wp', 'wpse27871_404_fakeout');
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "htaccess, redirect, permalinks" }
Easiest way to display post archives in category-then-alphabetical order? I've got a buddy who's trying to organize his recipe blog and would love to have an archive page that displays his recipes broken up by broad subject areas (read: categories) and then have the recipes listed alphabetically under each section (similar to this). Do I need to go the custom query route, or is there a better way, or, even easier, a plugin with shortcode support? (My Google Fu is failing me, as is my WP.org Fu as well. I _swear_ I've seen something like this before but I can't seem to find anything along these lines.)
I found a plugin that does pretty much exactly what I need: List Category Posts. Just throw in a few shortcodes under some H3's and I'm golden. _grin_
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "categories, archives" }
Get the ID of the latest post Been all over looking for the best way to do this. I want to get the ID of the latest post of a certain post_type. How can I do this in the cheapest way possible (by cheapest I mean using the least queries, and no loops or post rewinding)? Surely there is a quick method?
$latest_cpt = get_posts("post_type=yourcpt&numberposts=1"); echo $latest_cpt[0]->ID The only cheaper way than above, I can think of, would be to write your own SQL query to just return the one post and only the column ID.
stackexchange-wordpress
{ "answer_score": 27, "question_score": 12, "tags": "custom post types, posts, query posts, query, get posts" }
Directly editing content on webpage, is it possible? Is it possible to edit a website live? I.e simply click on the text you want to change and start typing. I've found something like this - < It's not quite what I want but it's close. So instead of clicking on some kind of admin button to open up a window you would click directly on the webpage to edit the text. Is it even possible?
I can suggest < Probably its what you looking for.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "admin" }
Twitter/Facebook login for comments What plug-ins there are available to allow people to leave comments using their Facebook and Twitter logins? Any special considerations or recommendations? I am currently allowing comments with the email addresses (default setup), but there are certain problems in this approach (spam being one).
Both Simple Facebook Connect and Simple Twitter Connect have features to allow users to post comments using their Facebook or Twitter credentials. Among other things. Disclaimer: I wrote 'em both.
stackexchange-wordpress
{ "answer_score": 3, "question_score": -1, "tags": "comments, facebook, twitter" }
WP Cron is "half-failing" to insert posts I built a plugin for my company, which basically goes to tube sites, scrapes them for content, and posts them automatically in whatever state is defined (publish, draft, future, etc). Now, everything goes well when I manually add a post through the plugin: it opens a cURL to the sites, grabs the videos and embeds, takes thumbnails, posts titles, flawless. however, when I try to run it from the cron job using add_action('timelyTube', 'timelyPost'); and on the activation hook: wp_schedule_event(time(), 'hourly', 'timelyTube'); it works in the sense that it fires the function `timelyPost()`, but when it goes to grab the video, it's not able to do so, it grabs the thumbnails & titles, but not the embeds, meaning that the cURL is working, but something gets messed up in the process. if anyone has any idea about what to do, I'll be grateful, Thanks, Itai.
Well, I've found my own solution, thanks weston, but I believe mine is a bit easier :) from the function which calls to insert post, you do the following for simplicity's sake: kses_remove_filters(); wp_insert_post( $post ); kses_init_filters(); And voila! there's a new post.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "cron, wp insert post" }
get custom post type by tag Is it possible to retrieve post entry for a custom post type by tag, I have been trying with the following code, however it just locks me into a infinte loop. <aside class="supporting_images"> <?php /*<?php if($post->ID == 241) : echo apply_filters('the_content', '[slideshow=3]'); endif; ?> <?php the_post_thumbnail(); ?>*/?> <?php if($post->ID == 241) : ?> <?php $query = new WP_Query(); $query->query('tag=branding'); ?> <?php while ($query->have_posts()) : ?> hello <?php endwhile; ?> <?php endif;?>
You'll need to setup the post for the query by changing the following line to get rid of the infinite loop. `<?php while ($query->have_posts()) : $query->the_post(); ?>` If your looking for a custom post type, you'll need to specify that in the query arguments: `<?php $query = new WP_Query( array( "post-type" => "yourposttype", "tag" => "branding" ) ); ?>` You can see most (if not all) of the query parameters in the codex. <
stackexchange-wordpress
{ "answer_score": 4, "question_score": 5, "tags": "wp query, loop" }
What's the best "insert all images" plugin? I've tried several plugins that supposedly allow you to "insert all images" after using the flash based uploader to upload multiple images. However, I still haven't found one that ties in well with the latest version of wordpress in a non-hacky way. Which plugins the most for inserting multiple images? image
<
stackexchange-wordpress
{ "answer_score": 0, "question_score": 2, "tags": "images, media, uploads, customization" }
Get post image gallery link I am showing the featured image on a custom post template, and I want to insert a "more images" text link to the gallery of attached images. Wordpress has instructions for inserting the gallery directly via but I want just the link, or better yet a modal popup to view the gallery. I have tried a variety of plugins, but none seem to work out of the box with the featured image.
There's no such thing as a link to a gallery, a post has a gallery by virtue of it having child attachment posts, it's not a separate entity. You could achieve the modal window by using some sort of lightbox plugin and modifying the gallery shortcode to output the images as just anchor links with the same rel attribute and hide them with css. Obviously that's a bit of custom code, not sure if there's a plugin out there that already does this. Alternately, you could create separate gallery posts and embed a gallery from another post with the gallery shortcode, then link to those gallery posts.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "gallery" }
Custom styles.css sheet for visual editor I am trying to use my own styles.css for inside the body of the visual editor for my pages. However, when i add add_editor_style('styles.css'); to the functions.php page it doesnt change anything (font color, boldness, etc) inside the body of the visual editor. I use firebug and check to see if it even loaded the styles.css and i can not find that it has anywhere. What am i missing? Do i have to install tinyMCE for this to even work or does this work with the stock visual editor? Thanks, David
You don't have to specify a file for the editor style. Just use `add_editor_style();` in your `functions.php`, and then create a file called `editor-style.css` in your theme folder. You may want to look at some examples (e.g. Twenty Eleven) for some of the TinyMCE-specific rules, which **is** the stock visual editor you're referring to.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "functions, css, visual editor" }
Display Links in Excerpts? I'm having a problem with the_excerpt and can not find the answer anywhere... I simply want to allow links to be clickable when they are displayed via the_excerpt! There has to be a function for this, rather than relying on a plugin. But I can't find it and the advanced excerpt plugins are so complex that I am unable to find the small snippet which makes this work.
You can use the script I found here: < I've modified it to show links in the excerpt, and removed some of the other functions: <?php function keep_my_links($text) { global $post; if ( '' == $text ) { $text = get_the_content(''); $text = apply_filters('the_content', $text); $text = str_replace('\]\]\>', ']]&gt;', $text); $text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text); $text = strip_tags($text, '<a>'); } return $text; } remove_filter('get_the_excerpt', 'wp_trim_excerpt'); add_filter('get_the_excerpt', 'keep_my_links'); ?> The part that fixes it is `$text = strip_tags($text, '<a>');`. along with `remove_filter('get_the_excerpt', 'wp_trim_excerpt');`
stackexchange-wordpress
{ "answer_score": 11, "question_score": 6, "tags": "excerpt" }
Do I Need to Prefix Variables Inside Functions? Sorry, this is a noob question. But, I want to follow the best practices. I read that functions and global variables should be prefixed in plugins. So, for example, `myfunction()`, should be `lax_myplugin_myfunction()`. And a variable, such as `$myvar`, should be `$lax_myplugin_myvar`. Do I need to prefix a variable if it's in a function? For example, lax_myplugin_myfunction() { $count = 50; return $count; } Should I prefix `$count` and make it `$lax_myplugin_count`? Or I don't have to bother with it as it's in a function. What's the best practice? Thank you.
Functions - yes. Class methods - no (but prefix the class name). Variables - inside your functions/methods - no (like in your example); inside template files - yes, because there are lots of global variables exposed by WP in them, and you might get conflicts...
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "functions, variables" }
Create a registration form with a PayPal checkout fee? My client is looking to start taking online registration for their many conventions and events. Previously they handled this all offline with PDF documents and in person payment. I'm looking for either a plugin or a detailed FAQ that will help me integrate an online registration plus payment system into their Wordpress site. I'm open to both free and paid services. Any and all help will be greatly appreciated. On a related note (just for some background on the scope of the project), ideally the user would have their own account on the Wordpress site. And they would register for one or multiple events at any given time throughout the year. This may or may not be difficult to implement. It's something they'd like to have, but if it's too hard I think we might just go without it. Thank you!
Wordpress + Gravity Forms is all you'll need for this project. Gravity Forms even has paypal integration. Set up a registration form, add on payment and you're ready to roll. They have detailed instructions and tutorials on how to set everything up and a very active forum if you run into any issues.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "forms, user registration, paypal" }
Unable to apply theme to WordPress Network Site install I'm using media temple with a fresh install of WordPress in network mode. **With subdomains off.** define( 'SUBDOMAIN_INSTALL', false ); I've followed Media Temple's *wildcard configuration (not that I think it matters) and I'm finding that when I create a new site nothing is working except it displaying a very basic page. Any ideas what would cause this? <
Actually, it is because you set up wildcard subdomains. You don't need to set them up if you just want to use subfolders. Because of this, ` can be found, but ` can't.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "multisite, admin, subdomains" }
Equivalent to in_category() for subcategories Wordpress provides conditionals like is_home() and is_category(). I'd like a function to tell me if the current context belongs to a category that is a subcategory (so, not a parent). I tried this, but it returns true on any category (and subcategory) context function is_subcategory($category) { if (is_category()) { foreach ($category as $c) { if ($c->parent > 0) { return true; } } return false; } }
try this: function is_subcategory($category = null) { if (is_category()) { if (null != $category){ $cat = get_category($category); }else{ $cat = get_category(get_query_var('cat'),false); } if ($cat->parent == 0 ){ return false; }else{ return true; } } return false; } Usage: //to check if the current context is a subcagetory: if (is_subcategory()){ //its a subcategory; }else{ //nope is aparent category } //to check if a specific category is a subcategory pass its ID, eg: if (is_subcategory(12)){ //yes category with the id of 12 is a subcategory; }else{ //nope is aparent category }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "categories" }
Forcing absolute <img> src links in the RSS feed We are using relative image URLs in the post's HTML code. Looks like relative src links break on many RSS readers. By default, Wordpress does not seem to prepare post's HTML for feed too much. Does there exist any solution for post-processing the feed URL and encoring all links and src attributes to be absolute?
Relative URLs are considered bad practice in WP, because of such issues and that they can be much more complex to migrate. Basic approach to fixing this (not counting changing to absolute URLs everywhere) would be to filter `the_content`, while checking for `is_feed()`, and adjust links on the fly.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "images, rss, html, feed" }
Custom Post Formats Here's my use case: a client will be making numerous blog posts, some of which are portfolio pieces of his recent work. This sounds like a perfect use case for a Post Format, but no "portfolio" post format exists. Post Formats are meant to be standardized, common formats, such as gallery, quote, status etc. Unfortunately "portfolio" isn't in that list and doesn't seem to fit with any of the sanctioned post formats. Creating a custom post type for this seems like bringing a bomb to a bonfire and frankly doesn't sit right with me since the portfolio blog post fits right in with the chronological main blog. So should I consider extending post-formats (if that's even possible)? Or is that strictly taboo? What's another alternative?
You can't create custom post-formats. What you could either do is have a post category called portfolio and then use the body/post class specific to that to control the display on the front end, as this is what post-formats are designed for, or go for a custom post type. Personally I go by the idea that, if it makes the posting screen less complicated for the client to work with for a specific post type, then a custom post type is the best option. You can still include custom post types in your standard loop - < so you wouldn't lose that chronological order, it would just make it easier for the client to add portfolio posts, if they are to be so different to normal posts.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "post formats" }
Query the post which have a thumbnail I've got a highlight section on the header of my website which shows the title and the thumbnail of the last X posts having a thumbnail. Is there any custom query which allows me to retrieve only the last X post having a thumbnail? At the moment I'm retrieving the last X * 10 posts (because not all the posts have a thumbnail) hoping that in this result I'll have X posts having a thumbnail. After doing my query I add a condition: `if (has_post_thumbnail())`. This solution is really uncertain and ugly, a custom query with a thumbnail parameter would be great but I couldn't find any hint about it.
try to work this into your query: `'meta_key' => '_thumbnail_id'` <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "post thumbnails, query, thumbnails" }
List of contents of entire blog There is a widget categories which prints categories as tree, for example: category1 subcategory1 subcategory2 category2 subcategory1 I would like to print whole content of blog together with articles not as widget but on main page as normal text like: category1 subcategory1 news1 news2 subcategory2 news1 category2 subcategory1 news1 news2 What is the way to do this?
there is some idea in 'Hierarchical Category List with Post Titles' which might need some adaptation to get exactly what you want.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "customization" }
Wordpress Author Page Whenever I click on the Author link, I get redirected to the home page. I've set up the author.php page according to the instruction on codex, but still no luck. Does anyone have any other suggestions?
Under the plugin's settings SEO > Indexation, scroll down to Archive Settings and make sure 'Disable the author archives' isn't checked.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "author" }
Which file of wordpress manage plugins functionalities? Which file of wordpress manage the plugins functionalities. For example if a have to insert another rule in a plugin functionality where i go to modify?
There should never be a case where you edit the core. Filters and actions were created so plugin developers could navigate the intricacies of Wordpress wihtout touching core files. You should reference the following: * < * < There are quite a few undocumented filters that I find when viewing WP core. If you do go to core, I would look for a filter that's being used in the area you wish to alter Wordpress rather than change the file outright.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "plugins, plugin development, functions" }
Stop Wordpress from "guessing" redirects for nonexistent URLs Wordpress sometimes "guesses" a redirection for a nonexistent page slug if the slug is at the beginning of another URL. After some searching, my hypothesis is that this part of the canonical redirection functionality, which can be disabled using this code: remove_filter('template_redirect', 'redirect_canonical'); However, I like the idea of canonical redirection, and would prefer not to turn it off entirely. Is there a way to only disable the slug "guessing"? I would prefer a 404 over an incorrect 301.
It's a bit hacky, but this should work: function no_redirect_guess_404_permalink( $header ){ global $wp_query; if( is_404() ) unset( $wp_query->query_vars['name'] ); return $header; } add_filter( 'status_header', 'no_redirect_guess_404_permalink' );
stackexchange-wordpress
{ "answer_score": 7, "question_score": 6, "tags": "redirect" }
How to add a second content section when using certain page template Is it possible to enable a second content area in the edit screen if a certain template is chosen? I have seen plugins like the second section plugin but that enables it for all pages I would like to only have the second section if a certain page template is chosen for a page.
You could add a metabox for your second content section, then hide it with a bit of javascript if the current template isn't a specific template: current_template = jQuery('#page_template').val(); if( current_template != 'my-special-template.php' ){ jQuery('#_your_meta_box_id').hide(); } then bind a function to the change event of the template dropdown and show it when a specific template is selected: jQuery('#page_template').change(function(){ selected_template = jQuery(this).val(); if( selected_template == 'my-special-template.php' ){ jQuery('#_your_meta_box_id').show(); } });
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "custom content" }
Trouble using get_post For Microkids related post plugin He said > "Using the get_post() function you could get any data you need from the related posts." and he posted this snippet of code. $related_posts = MRP_get_related_posts( $post_id ); I'm not exactly sure how to use the get_post feature for this situation. I would like to display the titles and thumbnail for each post in that array. Any help would be appreciated.
possibly: $related_posts = MRP_get_related_posts( $post->ID ); if( $related_posts ) foreach( $related_posts as $key=>$value ) { //only holds the following information: //echo $key; //the related_post_id //echo $value; //the related post title echo get_the_title($key); echo get_the_post_thumbnail($key); } (edited after downloading and testing the plugin)
stackexchange-wordpress
{ "answer_score": 0, "question_score": 2, "tags": "get posts" }
exclude category from get_posts? getting posts by cat with get_posts but need to exclude another cat called london or id 10. is this possible? best, Dc. // array(7,-10) $laargsM = array('category' => 7, 'posts_per_page'=>300, 'orderby'=>'title', 'order'=>'asc' ); $la_shapes = get_posts( $laargsM );
as 'get_posts()' uses the 'WP_Query()' parameters, i would assume that this should work: $laargsM = array( 'cat' => 7, 'posts_per_page' => 300, 'orderby' => 'title', 'order' => 'asc', 'category__not_in' => array(10) );
stackexchange-wordpress
{ "answer_score": 12, "question_score": 6, "tags": "categories, get posts, exclude" }
Plugin or method of allowing user to rearrange custom post types with drag and drop? I'm using a custom post type entry to represent each person in an About Us page. When going to the About Us page, it displays the people in a side menu and if the user clicks on a person's name, it goes to a page about that particular person. My client wants to be able to order the people in the side menu. Is there a good way to do this? I'd prefer to allow the client to drag and drop the posts around to the right order similar to how the Page Manager works, but alas it does not work for custom post types. Any ideas?
Take a look at **`Post Types Order`** plugin which lets you Order Post Types Objects (posts, pages, custom post types) using a Drag and Drop Sortable JavaScript capability
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "custom post types, admin" }
How can I tell if I'm on a login page? There are functions for `is_home()`, `is_blog()` `is_single()` etc... What's the best way to tell if I'm on a page that is requesting that I login? I guess that would just be the wp-login.php page.
Paste this function in your functions.php or a plugin file: function is_login_page() { return in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php')); } and then you can use it like this: if(is_login_page()){ //this is a login page }else{ //not the page you are looking for }
stackexchange-wordpress
{ "answer_score": 8, "question_score": 3, "tags": "functions, hooks, login, actions" }
Saving Custom Fields Defined in BuddyPress' register.php I am writing a custom app for a client that is based on BuddyPress and WordPress. One of the requirements is a custom registration form. To accomplish this, I have managed to hack a custom register.php together inside of a child theme which does the trick. The part where I am stuck, however, is getting BP to save my custom fields without hacking the core. I understand that I might be able to use the "user_register" hook to save the fields but I am not sure if that is the best way and if it is where in the database to store the custom fields. Can anyone point me in the right direction? Thanks! P.S. I also need a second submit button that redirects to a different page than the normal one for further processing but I may be able to figure this out myself.
Without hacking core files your only option is to use `user_register` hook to save the custom fields and usually custom fields should be stored in the corresponding object meta table, meaning that if its user meta then store it in the `usermeta` table and if its post meta then store it in the `postmeta` table. As for redirecting after the submit, that really depends on how your form works, if its the regular form then you can simply add an hidden field with the redirect value, something like: <input type="hidden" name="redirect_to" value=" but if the form is custom and not really using the built in registration form then take a look at **`wp_redirect()`** function.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "buddypress, user registration" }
Plugin settings page template When creating plug-ins for WordPress, there are times when you need to make a settings panel. Sometimes, you need more than one page, and they can be quite complicated. So far, I have been programming/coding them alone. I try to make most of the WordPress original Admin design, but for sophisticated panels, I get a spaghetti of PHP and HTML code. Also, every time, I have to write code that gets the data submitted by the user, analyses and saves it, and return a response. What solution are you using for your plugins? Are you using a template engine, or just mixing PHP code with HTML? Are there ready framework that offers such a solution? **Update** I found the solution to this problem. It's provided by WordPress, and it's very simple and intuitive. This blog post describes how to use the settings API which allows to create a settings/option page with ease.
There are indeed some frameworks * WP Alchemy * Rilwis Meta Box Class * etc... google will lead your way, as well as the in site search for both packages.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "templates, dashboard, options" }
Wordpress adds extra width to post images container boxes when I insert an image into a post, the `<div>` that contains that image (and thus any caption) is set to be wider that the image itself. For example, I have added an image that is 211px wide. The `<div>` that houses the image has an element style of 221px. Is there a way, other than using javascript, to remove that, and have the box of equal width to the containing image?
something I wrote a while ago: 'Adjusting Caption Frame Width'
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "images, attachments" }
Pull a post based on a meta value in a custom post type I'm trying to display a post, from a custom post type based on a meta value in that post type, in this case a checkbox that says "if this is checked show it on the front page. Usually I write a query using meta_key = > front_event value => true. But this does not work for custom post types. So I have this: <?php $event =array( 'post_type' => 'Events', 'posts_per_page' => 1, 'order' =>'DESC', 'meta_query' => array( array( 'key' => 'front_event', 'value' => true )) );?> This also does not work. Can anyone tell me what I should be doing differently? Thank you! Nadine.
Try to wrap `true` with quotes <?php $event =array( 'post_type' => 'Events', 'posts_per_page' => 1, 'meta_query' => array( array( 'key' => 'front_event', 'value' => 'true' )) );?>
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "custom post types, meta query, metabox" }
Display Registered Taxonomies Another question. I have a custom post type called "Articles" Within that I have registered some taxonomies using register_taxonomy called "Article Topics" So my client would pop over to Articles, put in a new article, fill out the publisher, and link to where its published, choose the topic its about...all good. Except: How do i get those "topics" to display in the sidebar. How do i make a sub-nav out of registered taxonomies? Something like this: <?php wp_list_categories($args); ?> Is this even a good idea? Or should I just say to hell with it, and go back to categories, and ditch the custom post type? Thanks. Nadine
Have a look at the codex page for `wp_list_categories`. $args = array( 'taxonomy' => 'article_topics' ); wp_list_categories( $args ); For the taxonomy terms assigned to individual posts, `get_categories` also accepts a `taxonomy` argument.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "custom post types, custom taxonomy" }
tag.php doesn't work with tags on a custom post type post? here's another stumper. I have a tag.php page. It works fine, unless you click a tag that is in a post associated with a custom post type. Then it doesn't work. Its like that tag, doesn't exist. But its just a tag that's used cross site. I'm not too sure why? And the codex isn't helping much after a lot of searching. anyone ever run into this issue? I'm stumped. thanks. Nadine
If this is related to your other question, what you've got is a custom _taxonomy_ , so you need either a `taxonomy-{taxonomy}.php` template (in your case `taxonomy-article_topics.php`), or just a more general `taxonomy.php` template. (also, go back and accept answers to your other questions here if they've been solved!) **UPDATE** sorry, misunderstood your question- add this to your `functions.php` template file to show your custom post types on tag pages: function wpse28145_add_custom_types( $query ) { if( is_tag() && $query->is_main_query() ) { // this gets all post types: $post_types = get_post_types(); // alternately, you can add just specific post types using this line instead of the above: // $post_types = array( 'post', 'your_custom_type' ); $query->set( 'post_type', $post_types ); } } add_filter( 'pre_get_posts', 'wpse28145_add_custom_types' );
stackexchange-wordpress
{ "answer_score": 12, "question_score": 6, "tags": "custom post types, tags, templates" }
Plugin Posts 2 Posts : problems with the 'position' field I must be a bit slow, I still have problems with the position field in the Posts-2-Posts plugin. If I set a position to each connection in a given post (say 1, 2 and 3) I don't understand how to display these connections in this order. I thought this would do the job : $xxx = new WP_Query( array( 'post_type' => 'author', 'p2p_orderby' => 'position', 'connected_order' => 'desc', 'connected_from' => get_the_ID() ) ); It doesn't. The position field is just not taken into account at all, even if I remove the line « 'p2p_orderby' => 'position' ». What do I do wrong ?
Yes, it was actually 'connected_orderby' instead of 'p2p_orderby'. Also, this can be done via drag-and-drop since version 0.9: <
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "plugin posts to posts" }
How do I turn off the Admin Bar for all Subscribers? Maybe this is a stupid question. When a user logins to my Wordpress site with the Subscriber role, they have the WP Admin Bar appearing at the top of the page. The user can go into their dashboard and turn this off themselves. But how can I turn this off by default for all existing and new users?
function disable_admin_bar_for_subscribers(){ if ( is_user_logged_in() ): global $current_user; if( !empty( $current_user->caps['subscriber'] ) ): add_filter('show_admin_bar', '__return_false'); endif; endif; } add_action('init', 'disable_admin_bar_for_subscribers', 9);
stackexchange-wordpress
{ "answer_score": 5, "question_score": 1, "tags": "user roles, admin bar" }
Taxonomy Parent Name Was just wondering how I would modify this piece of code: <?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); echo $term->parent; ?> ...to display the parent name, rather than just an integer? Currently it returns the ID. Thanks.
<?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); $parent = get_term_by( 'id', $term->parent, get_query_var( 'taxonomy' ) ); if($parent): echo $parent->name; endif; ?>
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "custom taxonomy, templates" }
Convert a date to ISO8601 date format This is more of a PHP question than a WordPress one. I have a custom post type event that by default outputs the date as "September 11, 2011 9:00 am" format. I'm trying to format the post in < format, I have converted every other part of the post to that format (place,address, etc) except the dates. Any help on how to convert that format to ISO8601 ( date format ? Thanks in advance.
Use `the_time` or `get_the_time`, which accept the same format parameters as php's `date`. // assign to a variable $iso8601_date = get_the_time('c'); // or output directly the_time('c'); EDIT- converting formats with php: $date = "September 11, 2011 9:00 am"; $time = strtotime( $date ); echo date( 'c', $time );
stackexchange-wordpress
{ "answer_score": 8, "question_score": 1, "tags": "php, date time" }
Giving users an editable homepage/business directory I'm currently working on a site which requires a business directory for 80 tennants. In an ideal world I'd like the administrator to create a user for each business and a page in a custom post type. The user would then be restricted to editing and updating only that page. On the front end these posts would be listed on a page which is searchable. Has anyone encountered such requirements in the past, any tips, ideas. All feedback welcome.
I've seen Role Manager used to restrict editor access only to pages on which they have been designated as authors. Would guess it would work with custom post types.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "users, user roles" }
.htaccess and 500 error, extra character added I am having a weird problem. Every few days I go to my website and get an "Internal Server Error" - Or 500 error. I go into the .htaccess file of the site and notice it's been altered. One character is added at the end of the file. It's easy to fix and continue on, but it keeps happening. htaccess permissions are 644 and the error logs don't say anything about this so I don't know where to start. Anybody have an idea as to what's going on or point me to some information on this issue? here is the "altered" htaccess code: # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index-php [L] </IfModule> # END WordPress s <---See This?!
Assuming you're on Linux, if you go to your wp-content/plugins folder and run grep -R 'htaccess' * it should let you know if any plugins are addressing that file by name
stackexchange-wordpress
{ "answer_score": 3, "question_score": 4, "tags": "htaccess, 500 internal error" }
Redirecting posts in Wordpress to a specific page I created a page so that it would appear in my navigation menu. This page would however be my posts page (i.e. all posts would go here) and would also be my front page. I am unable to find anything other than editing the 'Home' in the theme file (none of the themes I tried had the 'Home' editable). In other words, I'm looking for something that would redirect all of my posts as a stream into my homepage that also has a link in the navigation menu. I tried looking at a lot of places for help in this, however I couldn't find anything useful. Thanks!
You should be able to do this with just having the front page show blog posts like it does by default. No need to make empty pages and redirect and all that. In the theme file that contains your navigation (quite likely `header.php`), look for something that looks like this: <ul> <?php wp_list_pages( /* maybe some stuff here */ ); ?> </ul> You can add a list item before `wp_list_pages()` that points to home, e.g. <li<?php if ( is_home() ) echo ' class="current_page_item"'; ?>><a href="<?php bloginfo('url'); ?>">Home</a></li> There's also a conditional in there that will add the `current_page_item` class if you're on the home page with blog posts.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "posts, pages, templates, loop" }
modify all posts of a category to "no comments allowed" I'm looking for a way to modify all posts of a certain category to be "no comments allowed" without going into each post settings, one by one, and modifying manually. Perhaps a MySQL statement? Thanks
On your posts screen, you should be able to filter by category and then select all and bulk edit to turn off comments. **Edit:** Bulk actions only apply per page (e.g. 20 posts or however many you have showing), so you'll either have to do it for each page of results or go up to screen options and increase the number of items that are showing on screen.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 3, "tags": "custom post types, posts, customization, comments, mysql" }
WordPress stats: OWA plugin overhead in the future I've found a really promising stats plugin, Open Web Analytics. It has everything I need, also, it is self-hosted, without tracking cookies. The only thing I'm getting worried about is the overhead both in performance both in database size. Does anyone have experience with this plugin?
I hadn't used this specific solution, but any self-hosted analytics in general should be considered potentially huge resource hog: * every async action in WordPress is effectively another WP core load, so if tracking code makes even one additional async request to back-end it effectively doubles the load; * stat logging by nature cannot be cached; * stat logging by nature needs database writes, which are much more performance-hungry than reads. Hosted analytics solution are popular exactly because analytics comes with performance challenges.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugins, performance, statistics" }
How to appending to the_content using add_filter with custom post type? I have a custom post type running fine, but some of the text in the page is the same for every post, so I want to add it in using a function. I have this set up: function new_default_content($content) { global $post; if ($post->post_type == 'custom-post-type') { $content = 'Test text here'; } return $content; } add_filter('the_content', 'new_default_content'); However when I refresh the page, I only see "Text test here" and not the the post's content (from the_content). If I comment out this function, the post content reappears. What am I doing wrong?
You're completely overwriting the content instead of appending it. You need to do something like `$content .= 'Test text here';` instead.
stackexchange-wordpress
{ "answer_score": 10, "question_score": 10, "tags": "filters, the content" }
Categories Listing and Highlighting current category item My query is on Wordpress and related to categories. I have a set of categories for my posts: All, Cat-a, Cat-b and Cat-c. a. When I click on the link to my posts page, I want to show an archive for 'All'. How do I generate a link to 'All' explicitly? Something of this kind? <a href="<?php bloginfo('url'); ?>">All Posts</a> b. I would also be displaying the list of categories (shown below). I would however need to highlight the current category (by default, All). <ul> <?php wp_list_categories('title_li='); ?> </ul> c. Also I would need all categories to be displayed whether they have posts in them or not. Any help on this is greatly appreciated. Thanks!
On the Codex page for `wp_list_categories()`, you can see the two following arguments that might help you: * `hide_empty`: Toggles the display of categories with no posts. The default is `true` (hide empty categories). * `current_category`: Allows you to force the `current-cat` CSS class to appear on uses of `wp_list_categories()` that are not on category archive pages. Note that `current_category` only accepts _one_ category ID. If you have a post that belongs to two categories, you will have to choose one.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "posts, categories, php, permalinks, array" }
Open NextGen gallery in same page? When I click on the album it takes me to the gallery page and it displays the image in a lightbox. Is it possible to show to the images at the same page instead of it taking me to the gallery page?
Go to: Admin panel -> Gallery -> Options -> Gallery and set the checkbox: "Deactivate gallery page link" "The album will not link to a gallery subpage. The gallery is shown on the same page."
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "plugin nextgen gallery" }
Manipulate Permalink I'm using WPML to translate a website. The only major issue I have with WPML is that you cannot have a page in different languages with the same slug. Therefore www.example.com/contact/ and www.example.com/fr/contact/ is not possible. To get around this I was thinking of saving the french version as www.example.com/fr/contact-fr/ in the database but have this transparent to the user. To do that I was thinking of manipulating the URL so the the user sees www.example.com/fr/contact/ but Wordpress handles it as if the page were www.example.com/fr/contact-fr/ Is it possible to do this with a function or rewrites?
i'm not familiair with WPML, but i do know that qTranslate has the feature your describing.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "functions, permalinks, plugin wpml" }
How to use JQuery Marquee in Wordpress? I'm using `<marquee>` in my homepage , I want to use jquery marquee instead , I've added script in my header , in usage it says i have to use `$('marquee').marquee(optionalClass);` , how and where i have to use it ?
WordPress comes with copy of jQuery bundled. See `wp_enqueue_script()` documentation for how to: 1. Register you script properly and make it load jQuery as dependency 2. Use required noConflict wrapper so you can use jQUery functions (simply `$` won't work in WP).
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "jquery, html" }
How to end this loop properly? I´m using several similar loops to loop in content from different categories into different containers. If there are no posts in category X then it shouldnt open any container at all. Same with all loops. I´ve done this before, I open the container after "have posts" and put the divs belonging to each posts after "the post". But this loop ends differently from what I´m used to, so I dont know where to end my container divs. < How can I end the #wrapper-extra and .thumbnails properly?
Let's throw everything, but loop out: if ($my_query->have_posts()) { // open container around all posts while ($my_query->have_posts()) : $my_query->the_post(); // output for every post endwhile; // close containers around all posts } As you see: * output of posts goes inside `while` loop as usual; * opening larger containers is between checking `if` we have posts and `while`; * closing larger containers should be after `endwhile`, but still inside `if` block.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "loop" }
Using SMTP for outgoing mails (PHPMailer) on AWS instance? I moved one of my wordpress site to an AWS instance. But once I got it working, noticed that none of the notifications or contact emails were being sent through. On researching the issue, I found that if I set the SMTP server to be an external SMTP (my AWS instance doesn't have one), it should work. I don't need membership emails sent out from my site, just the contact form. So I tried 2 different approaches 1. Used the Configure SMTP plugin and configured it to route all emails via an SMTP account 2. Using Custom Contact Forms plugin, specified SMTP the settings so emails are sent using SMTP settings in PHPMailer None of these work. I am not getting any emails. The test email from Configure SMTP works but no emails are sent from the contact forms. Can someone please help me with what might be wrong? Is any additional configuration needed when doing this via AWS?
The plugin WP-Mail-SMTP has always worked for me. This is with the Contact Form 7 and many others as it replaces the WP Mail functions directly. <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 3, "tags": "contact, amazon, phpmailer" }
Is there a plugin that can replace WP comments with Facebook comments as used by TechCrunch? I've long been impressed by TechCrunch's Facebook comments, is there a plugin for WordPress self-hosted websites which achieves the same effect?
This is the official Facebook plugin: < supported both by Facebook and Automattic. Give it a spin.
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "comments, facebook" }
How to extract image width from add_image_size? How can I extract the width of an image as defined in `add_image_size` for use as a template variable? For example if my theme defines the size _small_ as `add_image_size( 'small', 195, 146, true );` _195_ would be the variable. I am trying to build a dynamic _mshots_ url.
Generally speaking, there's no need to do this. However, if it's one added using `add_image_size`, it will be in the $_wp_additional_image_sizes global. global $_wp_additional_image_sizes; echo $_wp_additional_image_sizes['small']['width'];
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "images" }
Weird google bot crawl problem I have moved my website to a VPS server. It is a Wordpress + Buddypress installation, latest versions. I don't understand why I can't see anything when I visit my site with Lynx - a text browser. I can see other sites using wordpress on the same server, but this one doesn't work. Also blogs created on the platform also work fine in Lynx, but the pages of the website don't. Guess that's why my website also was removed from google search results.
I have found the problem, there was a plugin activated for mobile browsers support - Smooci (WordPress on Mobiles). The plugin was enabled, and no theme chosen for it. So instead showing the default theme, the plugin, broke out my website - showing nothing/blank page on mobiles. Unfortunately the same plugin could not make the difference between a mobile browser and a text-only browser like Google Bot or Lynx. Deactivated the plugin and problem solved. Also posted a notice on wordpress forums: <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "buddypress, text, browser compatibility" }
Numbering lines of code with the <code> tag? The wordpress tag is used to display code on a page (refer to: < but I am having a hard time finding a function that will number the lines of code, as seen on < Does anybody know where this function can be found?
To get syntax highlighting with line numbering, you'll need to use a plugin like SyntaxHighlighter Evolved. In fact, looking at the source of that second link, it appears that they are using SyntaxHighlighter Evolved themselves.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "functions, tags, code" }
jQuery in header or footer From my reading it seems there is a good case for loading scripts like jquery and dependencies into the footer as a preference if possible; however 2 things confuse me which. Firstly the default for wp_enqueue_script() is to put the script in the footer and second (and possibly related) there is a line from the codex > Note that you have to enqueue your script before wp_head is run, even if it will be placed in the footer. Is this to say that even if the script is set to load into the footer it still loads early on and so we loose several of the advantages of footer placement? **Edit** \- Just in case the above incorrect statement confuses anyone in future. I realised since that I'd been reading the codex wrong and that the default for `wp_enqueue_script()` is **NOT** to put the script in the footer
There is a lot of leftovers in script-related articles in Codex that are not entirely correct (putting it mildly). The enqueue should not be done before `wp_head()`, it should be done on `wp_enqueue_scripts`. Which is technically early inside `wp_head()`. It doesn't harm performance, because registering/enqueueing script is merely explaining to WordPress how it should be done. Actual script output is done as separate print action. See my answer in where is the right place to register/enqueue scripts & styles for more detailed description of how things work.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 4, "tags": "plugin development, theme development, jquery, javascript, wp enqueue script" }
Star rating for custom post types I need to add star ratings to one of my custom post types. At first I coded them myself but when the rating challenge came along i thought about using a plugin instead, so I used easy post types. I've tried a couple star rating plugins and none of them seem to work. For example, with WP-PostRatings, I used the next code in my single-customposttype.php: <?php if(function_exists('the_ratings')) { the_ratings(); } ?> The image shows, but clicking does nothing. The same thing happens with other plugins. Star Ratins only says "an error ocurred" but no other debug info is displayed. So I don't know if you could recommend alternate plugins or any alternate method to add the star rating feature for my custom post type, because can't get it work as it is.
For any rating functionality I always turn to GD Star Rating by Milan Petrovic. This plugin can do SO many things, including thumb rating, rating of comments, multiple ratings, etc. It can also handle Rich Snippets (for getting your star ratings shown in Google SERPs), caching mechanisms, etc.. In short, it can do a lot, and I generally use it because of its flexibility and capabilities. You might need to change the code depending on your site, but here is how I have implemented it on one of my sites (in 'single.php' template file): if (function_exists('wp_gdsr_render_article')) { wp_gdsr_render_article(10, false,'',16); } Warning: You will want to familiarize yourself with the settings of the plugin and read up on the documentation, but it will be time well spent.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "plugins, custom post types, rating" }
How to Require a Minimum Image Dimension for Uploading? I need a way to restrict authors from uploading images bellow specific dimensions. Say I only want to allow uploading images that are at least 400px x 400px. If the image size is smaller, the author should get an error notice that the image is too small. Is there a plugin or code that can accomplish this?
Add this code to your theme's **functions.php** file, and it will limit minimum image dimentions add_filter('wp_handle_upload_prefilter','tc_handle_upload_prefilter'); function tc_handle_upload_prefilter($file) { $img=getimagesize($file['tmp_name']); $minimum = array('width' => '640', 'height' => '480'); $width= $img[0]; $height =$img[1]; if ($width < $minimum['width'] ) return array("error"=>"Image dimensions are too small. Minimum width is {$minimum['width']}px. Uploaded image width is $width px"); elseif ($height < $minimum['height']) return array("error"=>"Image dimensions are too small. Minimum height is {$minimum['height']}px. Uploaded image height is $height px"); else return $file; } Then just change the numbers of the minimum dimensions you want (in my example is 640 and 480)
stackexchange-wordpress
{ "answer_score": 27, "question_score": 18, "tags": "uploads, images" }
Same Conditionals Not Working on Two Different Hooks Everyone! I am new to WP and trying to build a plugin. I have the following codes working properly: add_filter('the_content', 'say_hello'); function say_hello($content){ if(is_single() || is_page()){ print $content." Thank you for reading!"; } else { print $content; } } But the following codes don't seem to work: add_action('init', 'prepare_head'); function prepare_head(){ if(is_single() || is_page()){ // include javascripts wp_enqueue_script("jquery"); //some more js goes here (registered and enqueued)... //include css $styleSrc = plugins_url("css/style.css", __FILE__); wp_register_style("say_hello_style", $styleSrc); wp_enqueue_style("say_hello_style"); } } Am I doing it wrong? Help is much appreciated! Thanks!
`init` is too early for conditional tags, use `template_redirect` instead. have a look at the action reference to see the order they're executed.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "filters, hooks, wp enqueue script, actions, conditional tags" }
getting all values of a custom taxonomy if there is no post I am working on a real estate theme. I am using some custom taxonomies such as Listing Purpose and Property type etc. In my add Listing form I am displaying each taxonomy in a dropdown, for which to work accordingly, I need to manually select all the taxonomy values in a post first then I can see the dropdown being filled properly. Today, for a check I deleted all the posts and came back to add Listing page and the dropdowns were empty. My question is that is there any way that I need not to first select all the values in each taxonomy? hope i was clear enough to get a suitable answer.
Ok, I figured out how to do it and it was quite simple and I was unable to figure out till now. Thanks to @NetConstructor.com in his reply to the post Saving Taxonomy Terms made me realize that using get_terms function (which I was already using), there is an argument 'hide_empty' helps to do the magic. How noob I am... Thanks and hope it may help some others out there...
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "custom post types, custom taxonomy" }
How to Resize the Custom Post Images? am Having Custom Field named as thumb.i want to show the images using these custom fields.i want to be fix the image size. My code is <img class="thumb" src="<?php echo get_post_meta($post->ID, 'thumb', true) ?>" alt="<?php the_title(); ?>" /> i tried timthumb also like this <img class="thumb" timthumb.php?src="<?php echo get_post_meta($post->ID, 'thumb', true) ?>"&q=100 alt="<?php the_title(); ?>" /> any one help me. thanks in advance.
You'd be better off using the inbuilt Post Thumbnails, which were introduced in WordPress 2.9 - these are easier to use than custom fields and have things like sizing built in. Once you've enabled Post Thumbnails, you can set their default size using set_post_thumbnail_size and then use them in your theme with **the_post_thumbnail**
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, custom post types, plugin development, custom field, images" }
attachment.php code or tutorial I am confused about the exact purpose attachment.php ( and image.php) . I notice many themes dont have them. If single.php displays the image the way I want then is it OK to leave it out. On the other hand could i just make a copy of single.php for attachment.php and leave out the sidebar. The other thing that confuses me is that when I add a gallery to a post I get the option to open images in an attachment page but when I add a single image to a post it only gives me the option to open the image as an image file (outside of the theme - ie without menus etc). I cant understand the point of this. What is the point in having an attachment.php file for images (or an image.php file) if it isn't going to get invoked when someone clicks on an image. Ideally what i need is a good tutorial on attachments but I cant find any and i can find very little info in the codex.
This is part of the WordPress template system, it allows you to drill down and further customize output based in the template hierarchy, for instance if you want the attachments to have separate functionality/style then your `single.php`, you simply create `attachment.php` or go even further with `MIME_type.php` (like images). < Also you have 4 url options when inserting single images: custom url, file, post or none !enter image description here
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "theme development, images, attachments, gallery" }
How to load parent theme style.css? My WordPress site uses a theme that is a child of a parent theme. As required, both themes have style.css files. However, as far as I can tell WordPress only provides the mechanism to load the child theme style.css file. How do the parent theme styles get loaded? Is it necessary to manually import the parent theme's style.css file into the child style.css file?
At the top of your child themes style.css add: @import url("../twentyeleven/style.css"); Obviously replace `twentyeleven` with your parent themes folder. 2016 - This practice has now been replaced by declaring the 'Template' in your theme stylesheet header: Template: twentyfifteen <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "themes, child theme, css, parent theme" }
Give Editor Access To Sidebar I want to give the Editor Role access to editing the sidebar and it's contents. I have a text widget in there and in order to edit this text widget the user needs to be an admin - this sucks. How do I grant permission to the Editor Role that will give him access to edit the sidebar?
The `edit_theme_options` capability should allow the user to edit the sidebar as described on this page : < Code to add to `functions.php` $role = get_role('editor'); $role->add_cap('edit_theme_options'); **Edit:** This should work to prevent editor accessing themes or menus function custom_admin_menu() { $user = new WP_User(get_current_user_id()); if (!empty( $user->roles) && is_array($user->roles)) { foreach ($user->roles as $role) $role = $role; } if($role == "editor") { remove_submenu_page( 'themes.php', 'themes.php' ); remove_submenu_page( 'themes.php', 'nav-menus.php' ); } } add_action('admin_menu', 'custom_admin_menu'); I haven't had chance to test this, but it only removes them from the menu they may still be able to access them by typing in the URL directly.
stackexchange-wordpress
{ "answer_score": 23, "question_score": 16, "tags": "widgets, admin, sidebar, user roles" }
Where can I edit Admin Panel Page file I need to edit the "Help" section of the "Page" page in the Admin panel. Since wordpress doesn't allow multiple line breaks I need to make sure the user knows that if they add the " " tag in the HTML section they will achieve the line break so I figure what better place to add this than the help section. I can't seem to find the Page file though. Directory Help?
You can add the custom help by adding a hook to the page load e.g. `page-new.php` would become `load-page-new.php` function custom_help_page() { add_filter('contextual_help','custom_page_help'); } function custom_page_help($help) { $custom = "<h5>Custom Help</h5> <p>Custom help content</p>"; return $custom.$help; } add_action('load-page-new.php','custom_help_page'); //New page add_action('load-page.php','custom_help_page'); //Page, edits, updates etc. If you don't want the default help to still display, simply remove `echo $help;` Edited to return rather echo the values.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "wp admin, pages, contextual help" }
How to allow YouTube object embed in Wordpress 3+? I admin a Wordpress blog with a few dozens of users. Since we upgraded to version 3.1+ my users can't insert the YouTube embed tags into a post ( wordpress or TinyMCE removes them ). When I'm logged in as administrator, I can insert the , and tags. But my users cannot. What about the auto-embed ( oEmbed )? Well, my users are too dumb to figure it out. They get confused pasting the link on it's own line and making sure it's not hyperlinked. The idea of adding [embed] tags around the URL is too difficult for them. Basically, someone taught them how to copy the embed code and paste it into the HTML tab and that's all they know how to do. They don't want to change. How can I make them happy? I just want to allow the YouTube embed code in their posts. Any plugin or hack to do this? Thanks, and my dumb users thank you too.
Youtube now supports oEmbed by default as the first option and even automatically highlights the url. Go to the youtube video you want, click **share** , the url is auto highlighted for you, copy + paste into wordpress, it does not get any easier.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "html, embed, youtube, html5" }
Add a field to just ONE page I discovered the 'More Fields' plugin which allows an editor to control which fields appear on which types of items in WordPress. Problem is, I would like to control which pages appear on just ONE page. Example of this: \- About page has WYSIWYG editor & Image \- Contact page has multiple text fields From the looks of it, you have to create new page types, but each of them show up in a separate section in the sidebar. I would like everything to appear under my pages tab. Any help would be great.
Take a look at the Custom Field Template plugin. It supports adding specific custom fields based on various conditions, which range from broad to fine-grained. You can, for example, limit the display of a particular set of custom fields to a particular page id.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom field, templates" }
Editing Help Section I was trying to find the contextual help section for all the admin pages so I could add some additional text. The main pages I need to hit are the "Pages" page and the "Widgets" page but I'm not sure where to find the files for these. Anybody know file names where I can find the contextual help?
Do NOT edit core files! You can add to or override the default text by using a filter. Try taking a look at <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "widgets, admin, pages, links, contextual help" }
Get password when user registers and save it sha1 into database im working on a website where the users can connect with iphone to some functions of it by using a sha1 encrypted password. In other words the plain password of wordpress encrypted in sha1. In the past i did the silly thing of editing the core files of wordpress to get the password when the user register and save that password in sha1 on the wp_users table. Of course my client updated wordpress and all the functions were lost. Yeah im stupid, im not sure what i was thinking that day. There is any way to hook to the register function to get the password , encrypt it in sha1 format and storeit in the database from the functions.php file of my theme? Any ideas?
Have a look at Pluggable Functions in `/wp-includes/pluggable.php`. You can safely replace the password generating/checking functions with your own.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "theme development, functions, filters, hooks, password" }
Display list of Sub-Categories and the posts they contain, within one main Category I've found tons of code and plugins to do various things; from show posts for specific cats, subcats of a cat, etc.. BUT, I cannot for the life of me find, nor do I know the WP API well enough to do what I need with it.. Here is what I'm trying to accomplish: Display a UL of all subcats within Cat31, and the posts for each of those subcats: * **SubCat1** * Post 1 * Post 2 * **SubCat2** * Post 1 * Post 2 * **SubCat3** * Post 1 * Post 2 It's pretty straight forward, but all the loops I have tried fail either at the subcat loop or the post loop (one or the other works, I cannot get them both to work..) So, unless I can find a plugin to do this (I'd prefer to code this into a template file!) then I need to figure out how to: Loop Subcats within Cat31 while looping subcasts, loop posts for each subcat Any help is GREATLY appreciated!
Question was answered on another site.. thank you! BTW, the code that accomplished what I needed was: $categories = get_categories('child_of=31'); foreach ($categories as $category) { //Display the sub category information using $category values like $category->cat_name echo '<h2>'.$category->name.'</h2>'; echo '<ul>'; foreach (get_posts('cat='.$category->term_id) as $post) { setup_postdata( $post ); echo '<li><a href="'.get_permalink($post->ID).'">'.get_the_title().'</a></li>'; } echo '</ul>'; }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 3, "tags": "categories, archives, loop, list" }
Plug-in (Slickr Flickr) works on local machine, but not server I am running Wordpress (3.1.4) with Slickr Flickr (1.3.2). I built a theme on top of thematic (0.9.7.7). Everything seems to work fine on my local machine and I can render Slickr Flickr galleries in the them templates without issue. However, when I enable the plug in on our server I get this error: Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/amsfcom/public_html/2011/wp-content/plugins/slickr-flickr/slickr-flickr-oauth.php on line 5 I saw a few questions with answers that seemed to be due to PHP 4 and protected methods. I don't think this is the issue because the server uses PHP version 5.2.9 on Linux. Locally I am using a Mac with PHP version 5.2.15. Could this difference cause the problems? Is there a way I can start to track down why this is?
I am pretty sure this is down to your site running PHP4. I suspect that your server has both PHP5 and PHP4 installed and happens to running PHP4 on this site. You can verify this by uploading a file version.php to your web root folder containing the following PHP command `<?php echo phpversion(); ?>` Regards Russell
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, errors, server, local installation" }
Insert pagination links - wp_link_pages() - before filters on posts I'm trying to add pagination support for some longer posts on my site. I've added the `wp_link_pages()` function to my single.php file, after `the_content`, but this causes the pagination links to display under some end-of-post plugins I have (YARPP and Better Author Bio, if that matters). I'd like the pagination links to appear at the end of the actual content, before any filter hooks are added. How can I do this without editing the the `get_the_content` function in wp-includes/post-template.php? Do I need to write a plugin?
That's because you have directly edited the single.php file, try to make a function and in it return `wp_link_pages()` and in add_action set a priority. Try this function function pagination_after_post() { return wp_link_pages(); } add_action('the_content','pagination_after_post',1); My WP PHP is not that good, my function might be wrong, this is just an example, but this way you can get pagination exactly after post
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "pagination, wp link pages" }
Moving a blog from a subdomain to a folder I'm going to move my blog from < to < the main Wordfruit site is in PHP and the blog is WordPress. I know I can make the change at wp-admin/options-general.php ...I want to make sure I don't create problems when I make that change... 1. Do I not need to create any folders etc on the domain? Will they just create themselves when I make the change? 2. Can I redirect the old urls to the new urls from within the WordPress account? 3. Are there any other things I need to account for in making this change? Cheers, Richard
First you should read the Codex entry on domain moving < But in a nutshell: aside from moving your contents phisically to the /blog location, all you have to do is search and replace every SQL entry for the previous domain (instead of just changing the domain in Wordpress options). Doing this by hand is pretty dangerous, I found this script to be very helpful: < Backup your database (eg. with PHPMyAdmin) in SQL form, then upload the above php script to your host folder, and point your browser to it. Using it you can safely search & replace < to < All your post contents and options will be then rewritten to the new domain. What possibly could remain is your page template - if you made it yourself, I'd also download and search the contents the theme folder for possible hard links to the old domain.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "subdomains" }
Get most recent media upload Wordpress sites this as an example of how to get the thumbnail: ` <?php echo get_the_post_thumbnail( $post_id, $size, $attr ); ?> ` I want to know how can I use the same basic function but just have it automatically get the latest media upload's ID number instead of having to specify the post_id.
I don't think that you can use `get_the_post_thumbnail` function to get last uploaded media, but you can use `get_post` to get latest attachment and then wp_get_attachment_image to display images. $attachments = get_posts( array( 'post_type' => 'attachment', 'posts_per_page' => 1, 'post_status' => null, 'post_mime_type' => 'image' ) ); foreach ( $attachments as $attachment ) { echo wp_get_attachment_image( $attachment->ID, 'thumbnail' ); }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "php, images, uploads" }
Need Header slider plugin recommendation i want the plugin to show header image slider with pagination and the images are **capable to change threw the admin panel**.* _integrating via theme_ *(template part) is very important. I tried wp-nivo and nivo jquery slider but it doesn't support to change the images threw admin panel. am diggingmy head for past 2 days.any one help me to get rid of this problem. thanks in advance
Have a look at Wordpress Skitter Slideshow. It allows setup of the slideshow images via the WP admin. You can only control _one_ slideshow on your website.
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "plugins, plugin recommendation, slideshow" }
SQL query to extract only the "current" wp_posts? The wp_posts table seems to retain all revisions of the same, ok very similar but presumably different, posts/pages/whatever. I'm somewhat conversant with SQL but not WordPress. I need to extract just those records which would appear on the public facing site; so just the most recent revision, and not all the superceded rows. Not sure how to filter the fields. Obviously something more complicated than: select * from wp_posts where post_status in ('publish','revision') order by post_modified desc which has 'duplicates' and seems to miss some stuff.
Rather than constructing query from scratch, it is easier to see what exactly is WordPress querying when API function is used: get_posts(array( 'numberposts' => -1, )); var_dump( $wpdb->last_query ); Gives following SQL: SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish') ORDER BY wp_posts.post_date DESC
stackexchange-wordpress
{ "answer_score": 10, "question_score": 7, "tags": "sql, posts" }
How to create a drop down menu like in twenty eleven theme? I really like the drop down menu solution of twenty eleven theme: < and would like to create a similar one but I cannot figure how it works, or is it based on some existing code for dropdown menus? Is there any source code that can be used, or can someone explain the principle behind it? I know internet is full of both js and non-js solutions, I've even made some myself, but IMO nothing comes near this menu, so help is appreciated:)
I was just doing exactly this recently. Not sure how advanced you are so you may know some of this stuff already. I found this video to be very good (+ it's second part) I think one of the original pieces of research done was this I think Twenty Eleven also uses the superfish jquery plugin As the other poster mentioned you can find the twenty eleven code itself somewhere amongst the theme files
stackexchange-wordpress
{ "answer_score": 1, "question_score": 3, "tags": "theme twenty ten, dropdown, theme twenty eleven" }
audio link produces black box In chrome and firefox (and maybe others) the audio link does not render a media controller. E.g. [audio In Chrome, view page source show this code in place: <div id="mep_0" class="mejs-container" style="width: 400px; height: 30px; "> <div class="mejs-inner"><div class="mejs-mediaelement"> <audio id="wp_mep_1" preload="none"> <object width="400" height="30" type="application/x-shockwave-flash" data=" <param name="movie" value=" <param name="flashvars" value="controls=true&amp;file="> </object> </audio></div><div class="mejs-layers"></div><div class="mejs-controls"></div><div class="mejs-clear"></div></div></div> UPDATE: In the JS console I note an error: mediaelement-and-player.min.js:36 Uncaught TypeError: Cannot read property 'url' of undefined
Your shortcode: [audio should be: [audio src=" Note the `src=""` around the filename.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "audio, html5" }
Pass variable to hook. Its possible? I have this hook created to retrieve user password when he register or update his pass. I dont want my client to touch wordpress core so i was planning to use a hook in wp-includes/user.php All this come from this other post as i cant find any other better solution MY problem is that the hook is being called but variables are empty. function encrypt_password_function($pass, $id){ global $wpdb; $encrypted=sha1($pass); $wpdb->query($wpdb->prepare("UPDATE wp_users SET iphone_pass = %s WHERE ID = %d",array($encrypted, '10'))); } function encrypt_password() { do_action('encrypt_password'); } add_action('encrypt_password', 'encrypt_password_function', 1);
Ok i can pass variables to hook but i was doing it wrong. Code should be: function encrypt_password_function($pass, $id){ global $wpdb; $encrypted=sha1($pass); $wpdb->query($wpdb->prepare("UPDATE wp_users SET iphone_pass = %s WHERE ID = %d",array($encrypted, '10'))); } function encrypt_password($var1, $var2) { do_action('encrypt_password',$var1, $var2); } add_action('encrypt_password', 'encrypt_password_function', 1,2);
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "theme development, functions, filters, hooks" }
Multiple post types in archives (filter?) I'm trying to get all custom post types to appear in my archive sections on a site, including monthly, tagged, author archives. At the moment, I've thought of something like: add_filter('pre_get_posts', 'sw_custom_post_type_includes'); function sw_custom_post_type_includes($query) { $post_type = array('post','custom1','custom2','custom3'); $query->set('post_type',$post_type); return $query; } But I don't want to use pre_get_posts, as this messes with all queries. Is there a filter for, in effect, pre_get_archives? Can't seem to find a solution on Google.
Try this: function sw_custom_post_type_includes($query) { $post_types = array('post','custom1','custom2','custom3'); if ( ! is_archive() && ! in_array( get_post_type(), $post_types ) ) return $query; $query->set( 'post_type', $post_types ); return $query; } add_filter('pre_get_posts', 'sw_custom_post_type_includes');
stackexchange-wordpress
{ "answer_score": 5, "question_score": 2, "tags": "custom post types, filters, archives" }
Is there a hook that runs after a user logs in? I am writing a plugin that fetches some extended user info from a remote service and I need it to execute its function each time a user logs in. Is there a hook that gets fired after login that I can add an action to?
The action hook wp_login runs when the user logs in - it can run a simple function. function do_anything() { //do stuff } add_action('wp_login', 'do_anything'); documentation : < The real breadwinner here is `wp_authenticate` which has a bit of documentation. It passes an array with the given username and password, which gives you the opportunity to pass info to the remote service, if necessary. < and to change the redirect URL after login, there is the filter `login_redirect`: <
stackexchange-wordpress
{ "answer_score": 47, "question_score": 33, "tags": "hooks, login, actions" }
should i be checking for jquery before enqueing it in a plugin At the start of a typical plugin which uses jquery I have something like the following wp_deregister_script('jquery'); wp_register_script('jquery', ' false, '1.3.2'); wp_enqueue_script('jquery'); Which as I understand it deregisters and re-enqueues jquery ( from google in this example but that's irrelevant here ) My question is this: is there not some way of checking to see whether the library is already enqueued ( by another plugin or the theme) to save needless deregister/register and enqueue ( or is this not very expensive in reality )
Enqueues are not piling up if done multiple times (that is kinda the point of having a queue). As for registration - frankly it shouldn't be done by most (public) plugins. WordPress comes with jQuery to use and when that copy is re-registered to something else - it affects all plugin and theme code that depends on it. If it's private code - just do registration once somewhere, no need to duplicate it.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "plugin development, jquery, javascript, wp enqueue script" }
Membership Plugin I'm looking for a good plugin for premium blog content. My client wants to offer 30 trial that's free as well as a paid monthly/6 months/yearly plan. It should display an except of the post for everyone even when they're on the site as a guest without any membership, trial or premium. It also needs to receive payments through PayPal and automatically turn on the subscription after payment. I want to be able to customize the register page to add additional fields like address and phone number.
There's plenty out there, < has a good write up on most of them and stays pretty unbiased. I can't tell you a good one but if you come across Magic Members stay well clear of it. It's buggy as hell and their support staff only help if its an easy fix. When you point out something that actually doesn't work they simply ignore your request for support.
stackexchange-wordpress
{ "answer_score": 2, "question_score": -1, "tags": "plugin recommendation, membership, plugin members, members" }
Wordpress Hacks/Defacing Im trying to figure out how Wordpress sites become defaced/hacked. I know development very well. I know how to secure code, etc. But I am finding recently, that tons of Wordpress sites are becoming defaced. Both sites I developed, and others. Is it simply outdated Wordpress installs? Even when Wordpress is running version 3.1, sites are still being defaced. All user input is validated, both on the front-end and back-end. WP nonces are used wherever possible. Servers are fairly secure (not 777). ???? I'm loosing faith in Wordpress. If it is my fault, I will gladly admit and fix, but the only answer seems to be outdated Wordpress sites, and I find that hard to believe.
> Even when Wordpress is running version 3.1, sites are still being defaced. _Even_? There had been one major and **five** security releases since that version. If you are implying that 3.1 should be reasonably secure - it is not. > but the only answer seems to be outdated Wordpress sites What had you done to exclude themes, plugins and hosting used to jump to conclusion that WP is sole possibility? If you are concerned about security of your sites had you considered hiring expert to perform proper security audit?
stackexchange-wordpress
{ "answer_score": 3, "question_score": -3, "tags": "security, hacked" }
Wordpress and Windows Live Writer I've just been trying windows live writer with my WordPress blog. When I upload my posts from WLW to WordPress and then check them in the WordPress editor, they are a hideous mess of tags etc that describe the formatting (e.g. `<P>` and no line spacing etc), but aren't visible when I create and edit in the WordPress editor. Is there a way to avoid this as it makes the WordPress editor very hard to use if I need to make edits outside of WLW. Or do people using WLW just give up on using the WordPress editor. I have to say I find the mess very offputting!
In this post, the poster had a problem of HTML tags being stripped of their opening and closing brackets when posting in WP from WLW'. He explains the source of the problem, and his solution: > The issue with the partially stripped HTML tags is a bug in libxml2. Specifically using anything less than PHP 5.2.9+ with libxml2 2.7.3+ is susceptible. The fix is to install a plugin into WordPress called LibXML2 Fix which you can get from your plugins menu or look here -> < He goes on in explaining how you can find out what version of PHP and LibXML2 you are running, so you know if you're suffering from the same problem as he is.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "windows live writer" }
Show selected value in a drop down menu I have a multisite setup and I am adding some additional information fields in the profile edit screen in my theme's dashboard. I am primarily using text fields however I have a drop down selection menu for the author's country <select name="country" class="mid2" id="country" value="<?php echo $userdata->country ?>" style="width:150px;"> My problem is that if a user selects "Togo" for example it registers the change (I know this because it echoes it in the author's bio page) but the default value in the drop down menu (In this case the United States) always stays the same. Any ideas on how I can have it display whichever country the author has selected?
Wordpress has a great little function built in for handling selections. <option <?php selected('value1', 'value2');?> value='foo'>Bar</option> You can also check out these form handling functions: * checked() < * disabled() < Your HTML syntax is wrong as well. Per W3C, 'value' is not an attribute of the select tag. The value of a select is defined in the options of a select. It should look like this: <select name="country" class="mid2" id="country" style="width:150px;"> <option value="US" <?php selected('US', $userdata->country);?>>USA</option> <option value="ES" <?php selected('ES', $userdata->country);?>>Spain</option> <option value="FR" <?php selected('FR', $userdata->country);?>>France</option> </select>
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "author, forms, dashboard" }
WordPress & W3C CSS Validation I've played around with WordPress here and there for a few years and am wondering about problems with CSS validation with WordPress themes. This may seems like a stupid question, but: Is there a reason, relating to WordPress, why it appears no themes I've run across come up error-free in WC3 CSS Validation? I thought of a number of reason this may be happening: * Those designing many themes not caring whether or not it pass validation * I'm getting my themes from not so great sources * There are quirks with WordPress that force designers to "hack" at their CSS Just wondering.
There's no reason a WordPress site can't pass validation, it's entirely up to the theme designer.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 2, "tags": "css, validation" }
Include home page template in specific category template I have a specific category who's page I'd like to look like the home page of my site, with all the nice sliding featured stories, etc. If I create a file `category-slug.php`, can I do some sort of include of the index template? If it helps, I'm using wootheme's FlashNews theme.
A somewhat ghetto but fast way to do this is to just use `get_template_part`, for example, get_template_part('index'); A better use for it is to grab "parts" of your template and not a whole index, but it still works. <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "categories, templates" }
Share plugins, themes, and multi post in a multidomain network I have created a network consisting of 3 sites (site1.com, site2.com, site3.com). Everything works fine, and I can access all three sites fine. What I need is to be able to share themes, plugins and post to all sites. I have tried multipost-mu, and ThreeWP Broadcast. When I create a post I can now choose the other two sites, but the post doesn't show up there. The way I set up my network is: 1. My host Setup the dns with a wildcard A record, and setup apache by adding ServerAlias *.|DOMAIN| to my httpd.conf 2. I then added the subdomain 3. I Edit the new subdomain: Changeg the value of Domain, Siteurl, Home, and Fileupload Url to suit to my new domain ( 4. I Edit my wp-config.php: define( 'DOMAIN_CURRENT_SITE', 'domain.com' ); changed it to define( 'DOMAIN_CURRENT_SITE', $_SERVER['HTTP_HOST'] ); What am I doing wrong?
Marja, By default any plugins in the wp-content/plugins directory will be shared across the site. You can **Network Activate** a plugin so it's activated on all sites. For themes, you will need to **Network Enable** the themes in the network admin panel. I'm not sure about the posts. That would be a support question for the plugin author that doesn't match the scope of this QA site. Hope this helps you out.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, themes, multisite" }
Add option to disable comments on a per posts basis? IN the past I thought there was a chackbox to enable/disable comments when making a new posts? I do not have that option when I make new post's, please help
Click on `Screen options` in the top right corner of the screen. And select `Discussion`. Than you'll see that checkbox to enable/disable comments. !enter image description here
stackexchange-wordpress
{ "answer_score": 11, "question_score": 6, "tags": "comments" }
Search Users base on meta_value & meta_key How can i use multiple meta_key and meta_value to search users? For example, i want to search & find user name is "David" & location in "London". I'm using this query, But nothings in result! $query = "SELECT user_id FROM $wpdb->usermeta WHERE (meta_value LIKE '%%david%%') AND (meta_key = 'first_name') AND (meta_value LIKE '%%london%%') AND (meta_key = 'location')"; $rows = $wpdb->get_results($query); Thanks
Your query is wrong that's way noting is returned because there is no row in the database that holds more then one meta_key. What you can do instead is create a Sub Query to get all user id's of users who live in London as a Sub Query and the use that to filter users id's of users who are named David, something like this: $query = "SELECT user_id FROM $wpdb->usermeta WHERE (meta_value LIKE '%%david%%') AND (meta_key = 'first_name') AND user_id IN (SELECT user_id FROM $wpdb->usermeta WHERE (meta_value LIKE '%%london%%') AND (meta_key = 'location'))"; $rows = $wpdb->get_results($query)
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "users, user meta" }
How to query posts by month based on date custom field? I currently created a custom field for a custom post type that stores a date in the format dd/mm/yyyy is there a way to query the posts by the month? I "kind of" got the functionality I need using the following query: `query_posts('post_type=attraction&meta_key=attraction_date&meta_value=10&meta_compare=LIKE');` The `meta_value` parameter would be the month but since I'm using `LIKE` to compare if I have a date like 10/04/2011 it'd be returned even though it's not from october. I know there's a `RLIKE` expression in MySQL that lets you use regex for the `LIKE` condition but I'm not sure if wordpress lets you use it in any way. Thanks in advance!
It is not clear what you're using as a comparison, but `WP Query` supports meta query comparisons and even has a DATE type. For example: $query = new WP_Query( array( 'post_type' => 'attraction', 'meta_key' => 'attraction_date', 'meta_value' => '10', 'meta_compare' => 'LIKE', 'type' => 'DATE' ) ); Using `10` is not going to get you very far, you should use a timestamp. I have not tested the date parameter in WP QUERY, it should be using/converting all dates to a unix timestamp using `strtotime`, if not I would suggest doing so. < <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom field, filters, query, date, order" }