INSTRUCTION
stringlengths
11
999
RESPONSE
stringlengths
0
999
SOURCE
stringlengths
16
38
METADATA
dict
Search returns everything if search term has a space When I try to search for terms with spaces, such as "lord of the rings", it returns all of my posts. However, if I just type "lord", it returns results. Any ideas what would be causing this?
Chances are it's searching using the 'OR' operand, which for will pull up everything that has those common words - 'of the'. There are a number of alternate search plugins for Wordpress - we've had great results (pun intended) using Relevanssi.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "search" }
Plugin Recommendation: Slideshow Gallery Delayed Image Loadging I am wondering if there is a WordPress plugin that creates a slideshow of images where: *flash isn't used *images are not all loaded at once and instead are loaded after page load I have a requirement for numerous images to be present in a slideshow that are high res. All images need to be stored locally (e.g. no flickr). I took a cruise through one or two plugins but they include all the images at once. Which murders page load times. Any suggestions?
I ended up using Really Simple Slideshow and manually integrating it into WordPress. Here is a link if this helps anyone: <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugin recommendation" }
Check if post has specific tag_ID in custom post type I am using Event Manager and they have a custom post type of events, with a taxonomy of event-categories (separate from regular post categories). In that taxonomy I have created terms(?) or event categories, "Education" and "Research". I want a specific `<div>` to show up if a post is in the event-categories taxonomy with the term/category of "Education". The slug is "education" and the tag_ID is 8. Currently I'm trying to use this code snippet, but I'm not getting it. I know there's more to it, but I haven't been successful with other tutorials. Most are for category archives. I need it conditionally for single posts. <?php if(in_category('education')) { echo '<div>test</div>'; } ?>
`in_category()` is conditional tag for taxonomy 'category'. With custom taxonomies you should use `has_term()` conditional, first parameter is term to check for and second is taxonomy. if ( has_term( 'education', 'event-categories' ) ){ echo '<div>Test</div>'; }
stackexchange-wordpress
{ "answer_score": 5, "question_score": 0, "tags": "custom post types, custom taxonomy" }
Multisite Plugin - Access options (wp_options) on child sites Is there a way I can access the `wp_options` table of all the child sites? I want to create a multisite plugin that can be setup at the network level and will populate the child site plugins with defaults that can then be overwritten by the each individual site. I'm aware that I could read/write from `wp_sitemeta` this way, but in my instance, it would make sense if I could access the other "local" tables. I could probably write a custom query using the WP query function, but I was wondering if there was a better way?
Try `get_blog_option()`. It does not use `switch_to_blog()`, and so introduces much less overhead. <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, multisite, options" }
wp-signup.php example template I'm looking for an example wp-signup.php template for which to work with. I've done a search in Google but nothing from the past year comes up. :/ I've tried: template-dir/registration/activity.php template-dir/registration/registration.php (these are BuddyPress I think)
You have to copy the original wp-signup.php file, do the changes you need and use it in your theme as a custom template.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "user registration, signup, wp signup" }
Date not appearing in custom query I'm having a weird issue with Wordpress which I cannot solve by myself, and for which I couldn't find an aswer over this and other websites. Basically, I have a custom loop. while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"> <?php the_post_thumbnail('featured'); ?></a> <div class="datetitle"> <div class="dateonly"><?php the_date('d.m.Y'); ?></div> <div class="titleonly"><?php the_title(); ?></div> </div> <?php endwhile; ?> <? wp_reset_postdata(); ?> If I then create another custom query similar to this one, or even if i just duplicate this query further down my page, I don't get the php the_date to return any value! this is the strangest thing... what am I doing wrong?
See `the_date()` in WordPress Codex for an explanation: > SPECIAL NOTE: When there are multiple posts on a page published under the SAME DAY, the_date() only displays the date for the first post (that is, the first instance of the_date()). To repeat the date for posts published under the same day, you should use the Template Tag the_time() or get_the_date() (since 3.0) with a date-specific format string. Use `<?php the_time(get_option('date_format')); ?>` to add the date set in the admin interface.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "wp query" }
Should I use the standard wp_mail() function for a premium theme? I am creating a premium theme that includes a Contact page template. Currently, I am using the `wp_mail()` function to send the contact email to the administrator-specified email address. Basically, I am wondering if the `wp_mail()` function is the best/expected choice for implementing email functionality in a premium WordPress theme? If it is not, what would be the better option?
Yes, you should use `wp_mail()`. There is no difference between a premium theme and a regular theme in this point. `wp_mail()` has many advantages and your clients will rely on it. If you break it, many plugins will not work anymore. Besides that, it is not the job of a _theme_ to change this functionality. There are plugins to replace the function.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "email, premium" }
How can I remove the site URL from enqueued scripts and styles? I'm dealing with an SSL issue and I would like to strip the domain from all scripts and styles being output via wp_enqueue_scripts. This would result in all scripts and styles being displayed with a relative path from the domain root. I imagine there is a hook that I can use to fileter this, however, I am not sure which one, nor how to go about it.
Similar to Wyck's answer, but using str_replace instead of regex. `script_loader_src` and `style_loader_src` are the hooks you want. <?php add_filter( 'script_loader_src', 'wpse47206_src' ); add_filter( 'style_loader_src', 'wpse47206_src' ); function wpse47206_src( $url ) { if( is_admin() ) return $url; return str_replace( site_url(), '', $url ); } You could also start the script/style URLs with a double slash `//` (a "network path reference"). Which might be safer (?): still has the full path, but uses the scheme/protocol of the current page. <?php add_filter( 'script_loader_src', 'wpse47206_src' ); add_filter( 'style_loader_src', 'wpse47206_src' ); function wpse47206_src( $url ) { if( is_admin() ) return $url; // why pass by reference on count? last arg return str_replace( array( 'http:', 'https:' ), '', $url, $c=1 ); }
stackexchange-wordpress
{ "answer_score": 18, "question_score": 10, "tags": "wp enqueue script, wp head" }
_n() Single and Plural for search results? This code produces > Search Results for "hello" - 1 articles " <h3>Search Results for <?php echo'"'?> <?php /* Search Count */ $allsearch = &new WP_Query("s=$s&showposts=-1"); $key = wp_specialchars($s, 1); $count = $allsearch->post_count; _e(''); _e('<span class="search-terms">'); echo $key; _e('</span>'); echo '"'; _e(' - '); echo $count . ' '; _e('articles'); wp_reset_query(); ?> </h3> How can I make it `$single` and `$plural` for eg. "1 article" or "2 articles"?
Instead of using 'if' loop it's better to use special function: <?php echo _n( 'article', 'articles', $count, 'my-plugin-domain' ); ?> <
stackexchange-wordpress
{ "answer_score": 6, "question_score": 1, "tags": "localization" }
How can I define the RSS feed content length? I’m trying to shorten the content of my RSS feed. Right now it displays way, way too much for each entry and I’ve tried to select the “Excerpt” in the Syndications setting in my option panel but it hasn’t done anything. I’ve tried different approaches but little has it helped. Is there a simple way (possible add_filter) where I can set the RSS feed content length to, say, 200? Thanks \- Mestika
I usualy make a RSS feed in my template. Just copy the RSS feed you have in the wp-include/feed-rss2.php Step two is registering it instead of the original: // override feeds function own_rss( $for_comments ) { //it is in my theme/feed/rss2.php $rss_template = get_stylesheet_directory() . '/feed/rss2.php'; if( file_exists( $rss_template ) ) { load_template( $rss_template ); } else { do_feed_rss2( $for_comments ); // Call default function } } remove_all_actions( 'do_feed_rss2' ); add_action( 'do_feed_rss2', 'own_rss', 10, 1 ); Step three is adjusting the your own RSS to your needs. also look at this: <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "rss, content, feed, excerpt, filters" }
How to check user's password? I am trying to check the passwords of users I created on my WP multisite, but the ones I find in the `sw_users` / `user_pass` do not match what I get when I do a _MD5 hash_ of the passwords I received during the user signup process. Here is an example from the table `sw_users`: (11, 'user5', '$P$BiwskWiaqZIQLzDUTAhSyvACr0Jpnl.', 'user5', '[email protected]', '', '2012-03-28 11:44:08', '', 0, 'user5', 0, 0), so I would assume that > $P$BiwskWiaqZIQLzDUTAhSyvACr0Jpnl. is the result of MD5 hash of the password. Is this correct? And why can I not match this when I run MD5 to the given password which is either > EJnltoRrQC6K or > fnxIwBW9Sjrm
Wordpress does not just MD5 hash the password, it runs it through `wp_hash_password()` which in turn runs through the `$wp_hasher` (a global object) `HashPassword` method. This does some hsld crap to include getting random bytes of data, salting the password, and encrypting it. Basically it's doing a whole lot more than an md5 to make it VERY difficult to reverse, even if you have the hashed password.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "password" }
Detect category choice for posts with multiple categories On my single template, I wish to show other posts in that category. Its essential that I use the route they chose, i.e. if they clicked Category 1, then Post A, if Post A is also Categorised as Category 2 and Category 3, I only want to show posts from Category 1 because that is what they originally chose. Is this an option? Is there a way to store some sort of global variable which I can set on my category page, then utilise on my single page?
Use: get_query_var('category-name'); Which will give you: > example.com/ **category/subcategory** /my_post Which you can then put into any queries you make under `category-name`. You can see this in action using the Monkeyman rewrite analyser plugin, by entering one of the URLs for a post and seeing the query variables it generates using those rules
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "categories, page template" }
Google Apps login in wordpress I manage a google apps domain with plenty of users; I would like to join Google apps with a Wordpress based intranet app we're creating. Which level of integration could I expect to achieve? Our hope is to create users in wordpress using their google apps email and let them login using their google apps password, so that they don't need to remember two different passwords. How would you suggest we should implement this?
Use the plugin Wordpress Social Login: < Does exactly what you want except the user doesn't actually have to type in their username and password if they are already logged in to Google Apps - they just click the Google icon and it will log them in to WordPress using Google Apps. And yes, you can create users in WordPress first tied to Google Apps email addresses and then the users can login without needing a registration step. It provides other auth options (FB, Twitter, etc.) if you'd like.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 9, "tags": "user registration, openid" }
filter the_title problem in nav Hi I have a problem with the_title filter: I have this code at my constructor: add_filter( 'the_title', array($this, 'change_title') ); and this as callback (for testing purposes) public function change_title($title) { return 'title'; } But is filtering my navigation items! instead of show home, pages, etc all changed to `'title'` !screenshoot Any Ideas how to fix it?
You can try the `in_the_loop()` conditional to check if the context of `the_title` is within the loop.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 2, "tags": "filters, hooks" }
difference between add_object_page and add_menu_page According to Codex, the `add_object_page` "essentially does the exact same thing as `add_menu_page()` in case you're wondering". So.... what _is_ the difference between those two functions?
It's just a wrapper for `add_menu_page()` with one addition: > It adds the menu page as absolutely last/to the bottom of the menu.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 3, "tags": "functions, wp admin, admin menu, add menu page" }
why doesnt is_home() work in functions.php I'm pulling in scripts.php through functions.php. this is in scripts.php but for some reason, wordpress isn't recognizing is_home(). i've tried resetting the query, but to no avail. Am I hooking into the right function? if(is_home()){ function my_scripts_method2() { wp_register_script('cycle', get_template_directory_uri() . '/js/cycle.js', array('jquery')); wp_enqueue_script('cycle'); } add_action('wp_enqueue_scripts', 'my_scripts_method2'); function my_scripts_method() { wp_register_script('homepage', get_template_directory_uri() . '/js/homepage.js', 'cycle'); wp_enqueue_script('homepage'); } add_action('wp_enqueue_scripts', 'my_scripts_method'); }
At the time _functions.php_ is included during bootup, WordPress has no idea on the contents of the query, and doesn't know the nature of the page. `is_home` will return false. Wrap the code in a function and have it triggered by the `wp` hook, which comes after the global query object has been hydrated with data. add_action( 'wp', 'wpse47305_check_home' ); function wpse47305_check_home() { if ( is_home() ) add_action( 'wp_enqueue_scripts', 'my_scripts' ); } function my_scripts() { ... } The `wp_enqueue_scripts` action runs after `wp`. <
stackexchange-wordpress
{ "answer_score": 10, "question_score": 4, "tags": "functions, hooks" }
How to add homepage Widget? How do I add a 'Homepage' widget to my widget bar in Wordpress 3.3 ??!! **EG:** Dashboard > Widgets > Homepage with same fields as others
I've had good luck with the Widget Logic plugin. It lets you use template-style logic for each widget. It's not quite the same as adding a whole new admin page just for conditional widgets (you would need to create and register a new sidebar, etc), but it's great for the quick-and-dirty 'get it in there now' needs.
stackexchange-wordpress
{ "answer_score": 2, "question_score": -1, "tags": "plugins, php, widgets" }
How can I make a post that belongs to a category or have specific tags, display different from the other single posts? How can I make a single post display different from the other single posts when I add it to a specific category. example: I have a post that is in 3 categories: music, songs & video clips. I want every time that I add a post in category "songs", it will be displayed differently from all of the other default single posts that don't belong to the category songs. How can I do that? Also, can the same thing happen with tags too? Meaning, when I add to a post some specific tags can it change the template of the post?
**With CSS** : If your theme uses `post_class()` on a containing element, you can target that element with the class `.category-songs` to control styling. **With a template filter** : add a filter to `single_template` and check the assigned categories for your `songs` category, and use the template `songs-single.php` if that category is found: function wpse_check_single_categories( $template = '' ){ $categories = get_the_category(); foreach( $categories as $cat ): if( $cat->name == 'songs' ): $template = locate_template( array( "songs-single.php", $template ), false ); endif; endforeach; return $template; } add_filter( 'single_template', 'wpse_check_single_categories' );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "posts, tags, single" }
WordPress theme options tabs It is possible to create tabs in admin panel in Theme options like in Theme? Please see this screenshot: ! I can't find any official documentation about adding admin tabs.
Wordpress includes many js libraries in `\wp-includes\js` and in `wp-admin\js`. You can browse through them and choose which one you want, including jQuery tabs. You can use it in your theme by using this function, < To figure out how to use the tabs, you would read about it here: <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "options, tabs" }
Plugin to book course and pay online for it I got a request from a client. He need to manage a school with courses 2-3 day a month. He have to open-close date and manage it easily. Then when a person choose a date, he need to register, and pay with paypal, get a confirmation and email send to the customer and the teacher.... Question, do you know 1 or 2 plugin that can help me get this done in WP ? thanks in advance
I am not sure it will do **exactly** what you want, but it sure can **help** you to start. < < < and many others that you can find here or in google
stackexchange-wordpress
{ "answer_score": 0, "question_score": 2, "tags": "plugins, paypal" }
Jigoshop search taxonomy I was wondering does anyone know how I can modify the search so it searches a taxonomy? at the moment it just looks for a product title, but not the taxonomy assigned to the post. Please help
You need to change the query settings before it is run. I'm assuming that you have a `search.php` page, but if not I'll tell you where to put the code at the end. In `search.php` add this to the very top of the file (above the `get_header()` call) - $args = array( 'posts_per_page' => get_option('posts_per_page'), 'paged' => $paged, 'post_type' => $post_type, // The post type that you wish to search $taxonomy => $term // Where $taxonomy is say 'cheese' and $term (must use the slug) is maybe 'cheddar'. Can be omitted if you do not actually wish to search taxonomy/terms. I think you can also pass $term as an array of terms - array('cheddar', 'brie', 'edam'). ); If you do not have `search.php`, nest the code as below and place it at the top of your `index.php` file - if(is_search()) : { Code from above goes here } endif;
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, search, jigoshop" }
How to get full slug, including all parent pages I am trying for hours and I managed to get full slug for parent of sub-page when I am on 3rd level sub-page I can not get slug of the top parent page. Example domain.com/top_page/sub_page/sub_sub_page I need to get full slug 'top_page/sub_page/sub_sub_page' I am doing this for language sites that are on sub-domains (individuals sites). These pages have same slug across sub-domains. So I want to link language site that when you are on some given page link to language site will take you to that page in that language (not home page of that language). example of hyperlink to English language sub-domain: echo '<a href="en.domain.com/'.get_FULL_SLUG).'">'English'</a>'; Is it possible to get slug of top parent when you are on third level page, sub-sub-page Hope somebody can help
This would replace domain.com/top_page/sub_page/sub_sub_page with /top_page/sub_page/sub_sub_page $path = str_replace(home_url(),'',get_permalink());
stackexchange-wordpress
{ "answer_score": 4, "question_score": 4, "tags": "slug" }
If no posts in category display Form instead of not found I have a couple of categories that don't contain any posts (yet). What I would like to do is have a form which takes users details for future posts. Am I right I thinking I simply edit the page which displays the current search bar.
In your category.php ( or custom taxonomy archive template ), you should add the form code in the else case of your check if there are posts e.g. if(have_posts()){ // do the post loop } else { // display a form that takes user details for future posts } If there is no category.php you can copy and rename your index.php, and you can do the same for individual categories, e.g. category-example.php will be sued instead of category.php for the example category
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "categories" }
How to generate video out of images via Wordpress plugin I am working on Wordpress plugin which can generate video from sequence of images. I read here that we can use FFMpeg and Imagemagick (or imagick) to implement this trick. But, FFMpeg is hardly supported on shared hosting. So, this option is ruled out. I started working on Imagemagick. But, I was informed here that both of the above options cannot be used for Wordpress. So, is there any feasible option for developing a video file out of images for Wordpress??? I am storing sequence of images in /images folder and want to develop and video out of these images. I appreciate any help.
What you're trying to do is likely to upset shared hosters regardless because generating video is not cheap from a computational resource standpoint, and most rules on a shared host are because there isn't much in the way of resources to begin with. You would be best carting your images off to a service that would do the job for you. Trying to duplicate the work of ffmpeg etc in PHP will likely exceed the execution timeout, so you're not going anywhere where shared hosts are concerned. You may be able to get away with GIFs, and keep ffmpeg support for those on a VPS
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "plugins, plugin development, php, images, videos" }
Remove Metabox from Menus screen Been digging into WP files for a bit and think I just might be missing something. The end-goal is to remove the `Theme Locations` metabox from the Menus screen if someone doesn't have a certain capability `manage_options`. I know, a little odd for usability, but there's only one menu and we're trying to make this harder to screw up ;) Looking at `/wp-admin/nav-menu.php` around line `383` I see `wp_nav_menu_setup()` so I tried to add the following as a filter, but with no luck so far: function roots_remove_nav_menu_metaboxes() { // Remove Theme Locations from users without the 'manage_options' capability if (current_user_can('manage_options') == false) { remove_meta_box('wp_nav_menu_locations_meta_box', 'nav-menus', 'side'); // theme locations } } add_action('wp_nav_menu_setup', 'roots_remove_nav_menu_metaboxes',9999); Any help would be really appreciated. Thanks!
The box gets added in wp_nav_menu_setup(), so you'll have to remove it sometime after that and before it's being output later in nav-menus.php. There don't seem to be any action hooks you can use there, but admin-header.php has a few. You could try this: add_action( 'admin_head-nav-menus.php', 'roots_remove_nav_menu_metaboxes' ); I've never tried removing metaboxes from the menu screen, though, and it's untested, so no idea if it works.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "menus, admin, metabox" }
Search by keywords with boolean operators Is there a way to tell WordPress to only search the keywords and nothing else? For example, if I searched "yellow, red, white" it would only display posts with one or a combination of those keywords in it. Is this possible in WP?
Try WordPress › Relevanssi - A Better Search « WordPress Plugins
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "search, tags" }
Get a user's most recent post title If I have a user's ID, what's the best way for me to get the title of that user's most recent post?
You just set the 'author' parameter in a `WP_Query` query or `get_posts` (which accepts the same parameters): $recent = get_posts(array( 'author'=>1, 'orderby'=>'date', 'order'=>'desc', 'numberposts'=>1 )); if( $recent ){ $title = get_the_title($recent[0]->ID); }else{ //No published posts } (Note the 'orderby' and 'order' here are redundant because they are set to their default values, but you get the idea)
stackexchange-wordpress
{ "answer_score": 5, "question_score": 2, "tags": "query" }
how to set category name for a post how to set category name for post: this is my code ,this is not working ,why? $post_title = $vname; $categ='category name'; $post_content = '[newpage link="'.$videos.'"]'; $new_post = array( 'ID' => '', 'post_author' => $user->ID, 'post_category' => $categ, 'post_content' => $post_content, 'post_title' => $post_title, 'post_status' => 'publish', ); $post_id = wp_insert_post($new_post);
The `post_category` parameter has to be an array of IDs ( _int_ ). < Try `get_category_by_slug` to get the ID, then use it. $category = get_category_by_slug( 'your-category' ); $new_post = array( ... 'post_category' => array( $category->term_id ) ); Alternatively, look into `wp_set_object_terms` or `wp_set_post_terms`, using the `$post_id` of the post you've just created. If you need to add a category that is non-existent yet, create it using `wp_create_category`. Good luck.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "php, categories" }
Graphics and Formatting Not Loading in WordPress on IIS We have IIS 7.5 and we've installed WordPress (v3.3.1) through the Microsoft Web Platform installer ( All works fine when we load WP locally (e.g. < the graphics load fine. But when I enter the IP address or hostname accessing the site from a machine other than locally, none of the graphics or formatting appear. Is there some configuration I have to set to get this working? I've noticed that all the graphics etc. are hard-wired to 'localhost', which explains why I'm losing the images when accessing from a remote machine. e.g. Help!!
Check that your WordPress Address and Site Address are correct under Settings > General. ie., if you want it to be viewable on another computer, this shouldn't say "localhost" anywhere...
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "images, installation, formatting, iis, configuration" }
Add HTML to Page Content I'm accessing a page content from outside WordPress, in a different webpage. Everything runs fine, I'm using this: require("wp-load.php"); $page_id = 300; $data = get_page($page_id); echo $data->the_content; However, the content is different from what WordPress would output normally. For example, paragraphs which are separated by blank lines in source come just like that, without `<p>` tags. How can I get the content from a page in the same way that WordPress would print it? Should I apply some other filter or use another function to process the text?
Indeed! It's a filter called 'the_content', to which numerous other functions are hooked such as the one that turns Wordpress into WordPress, oembeds, and the p tag wrapping echo apply_filter('the_content',$data->the_content);
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "filters, formatting, pages" }
Pods cms and "advanced custom fields" plugin We are planning to build a quite big database to store data for our 5000 yearly subscribers association. We were considering pods cms for our needs since it permits a good flexibility in building a complex website and is performance aware while managing the database. But recently I red on the pods cms website that they're having some funding problems, so they're struggling reaching the 2.0 milestone. We're afraid that the development could stop. On the other side we found "advanced custom fields" that also seems a good alternative. Furthermore it has a stronger business model. So what would you suggest me to do?
Development of Pods 2.0 definitely won't stop, the funding problems explained in that dev post were alluding to an upcoming announcement that we'll be pushing some of the enterprise and "extra" functionality of Pods 2.0 into a premium version targeted towards firms with more advanced and specific needs. On the data structure, Pods 2.0 handles post types, taxonomies, and more. It even will have a migration feature to move between different content types. You probably won't be worse off by going with ACF right now, and eventually having to migrate to Pods, as you'll have a solution that works well for you when you need it (now). Even if you don't use Pods, good luck with your project and I'm sure people would love to see the site you're working on when it's done if you find time to follow up with how it all worked out for you.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 3, "tags": "advanced custom fields, cms, pods framework" }
How can I remove "Proudly powered by WordPress" from twentyeleven without modifying footer.php? How can I remove "Proudly powered by WordPress" from twentyeleven without modifying footer.php, and without creating a child theme? I'm looking for a php command, such as `add_action`, `remove_action`, `add_filter`, or something of that sort. I'm not looking for CSS to hide the footer. I don't want to modify any of the theme files other than `functions.php` Is this possible? For reference the code in the footer that is creating this is below. <div id="site-generator"> <?php do_action( 'twentyeleven_credits' ); ?> <a href="<?php echo esc_url( __( ' 'twentyeleven' ) ); ?>" title="<?php esc_attr_e( 'Semantic Personal Publishing Platform', 'twentyeleven' ); ?>" rel="generator"> <?php printf( __( 'Proudly powered by %s', 'twentyeleven' ), 'WordPress' ); ?></a> </div>
There are 3 methods. 1. Somewhat weird but since this text is internationalized you can filter the output. This is just an example to remove the text, the link is still present in the source. add_filter('gettext', 'remove_powered_by', 20, 3); function remove_powered_by( $translated_text, $untranslated_text, $domain ) { $custom_field_text = 'Proudly powered by %s'; if ( !is_admin() && $untranslated_text === $custom_field_text ) { return ''; } return $translated_text; } 2. Use jQuery (or javascript) `$('#site-generator').remove();` 3. Create a child theme and just comment out the code or delete it.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 3, "tags": "php, themes, hooks, actions, footer" }
Is there a way to show different source feeds on individual pages? As a freelance writer, I have a few outlets I write for routinely plus additional sites, and while I used to post my content manually, due to SEO concerns and logistical issues, I have been looking to modify my Wordpress install to pull posts of mine from my client websites and display the content as it is added. I'm not sure if this is a valid comparison, but essentially I want to use Wordpress like Mahara which seems to be built for you to post all types of content, like a digital potfolo, all in one place. Although I did try Mahara ( for a short period, I ultimately went back to Wordpress because of the community and also the fact I'm used to using it for client projects and such. Thanks in advance for any assistance,
This is an answer to your title cuz' i couldnt understand the question in your explenation ;) **Sure... no need to even work hard. Here you can find an easy way to do exatly that with ready designs:** * feed2js.org Hope This helps, Sagive.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "import, custom content" }
Is it possible to load wp-content/uploads from another server? I just recently moved to my new CentOS server and I did a fresh installed and before I use to be with my Mac OS [Xserver] So what happen I was thinking about CDN and though that maybe this will somehow apply to some of the condition where it will make my site load faster because this is from another server. How or is it even possible for me to get the wp-content/uploads from another server?
Use any number of CDN plugins < or a cache plugin that also suports a CDN like WP Super Cache <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "multisite, cdn" }
Incremental number handling on duplicate file names After a couple of hours searching the WP core I've lost hope finding this myself (for once). Could someone guide me perhaps to where WordPress handles the incremental number when having duplicate file names during uploading? As a side question. When handling questions like this, where and how would you start searching? AFAIK I've searched through every file containing `file` and `upload`.
The number is added in `wp_unique_filename()` in `wp-includes/functions.php`. You can prevent it by hooking into `'sanitize_file_name'` and setting another file name. You can find such functions and filters by following the code with your IDE. Most IDEs make functions clickable so you can go from their call to their declaration. Here is an example from Eclipse PDT: !enter image description here
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "uploads" }
Reseting admin password through PHPMyadmin fails Following the PHPMyAdmin instructions of this article fails to reset my password properly. I go into WP_Users, find my admin account, click edit, enter my password, change the dropdown to MD5, click save, but this password does not work when I try to login to WP-Admin with this username. Confused.
Here is a picture explaning how to do it be carful and backup the database befoure any changes are done first here is a link to md5 encoder (youll need it): MD5 Encoder !howto change password in phpMyadmin . Hope this helps ;) Cheers, Sagive.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "password, phpmyadmin, reset" }
Wordpress 3.3.1 Page template not showing in admin area I have created a page with the php comment at the start of the file: <?php /* Template Name=> Team Detail */ ?> and saved it as team-detail.php in my theme's root directory. Now when I want to add a page with this as the template for that page, I cannot see this template in the admin area under ->add new page-> template. Have tried reactivating the theme to no use.
First of all, change `Template Name=>` to `Template Name:`. Also, when you say the themes root do you mean `wp-content/themes`? If so, keep all your files in a folder specific to your theme i.e `wp-content/themes/myTheme`. If you've done that, make sure you've got a stylesheet in your theme and that your permissions are set correctly on the themes folder. You should need 755 on your theme. You don't give away how familiar you are with WP themes so I'll just add a few links that might be useful; * WP Codex Pages * Anatomy of a WP Theme * WP Codex Theme Development
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "page template" }
protect user submitted posts I have a website that I am working on. I created an html form and put in some code that will take the form data and create a new wordpress post. It will post the information to a specific category. All is working. Now I want to know what I can do to protect the data being entered? Should I use php and write pregmatch statements for every input? I have 7 different inputs on my form. I was thinking that wordpress would already have some functions that I could use to validate the data to make sure someone isn't trying any bad things with my form. The users who will fill out this form will not be registered or logged in.
Take a look at WordPress codex **`Data Validation`** entry, it covers most of the validation functions that come built-in with WordPress which you can use to validate your form submission.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "validation" }
Post publish only hook? Is there any hook which is fired only when the post is "published" for the first time. I dont want to execute my code when the post is "updated" or when its status is set to "not-published" and then "published" again. EDIT: add_action('draft_to_published','func_tion'); function func_tion($post){ $post_id = $post->ID; if ( !get_post_meta( $post_id, 'mycoderan', $single = true ) ) // run code to manipulate data wp_enqueue_script('plugin_name',plugin_dir_url(__FILE__ ).'script.js'); $params = array() // set parameters wp_localize_script('plugin_name', 'params', $params ); update_post_meta( $post_id, 'mycoderan', true ); }
The `{$old_status}_to_{$new_status}` and `{$new_status}_{$post->post_type}` hooks tend to generally solve the problem. To avoid running the code in case post status is changed to draft then published again (after already being published), implement a simple flag using the `post_meta` functionality. **Note** : the updated hook should be 'draft_to_publish' instead of 'draft_to_published' however, the code below is not modified and should be if you plan to use in WP 3.5 add_action( 'draft_to_published', 'wpse47566_do_once_on_publish' ); function wpse47566_do_once_on_publish( $post ) { // check post type if necessary if ( $post->post_type != 'a_specific_type' ) return; $post_id = $post->ID; if ( !get_post_meta( $post_id, 'mycoderan', $single = true ) ) { // ...run code once update_post_meta( $post_id, 'mycoderan', true ); } }
stackexchange-wordpress
{ "answer_score": 5, "question_score": 4, "tags": "posts, publish" }
why does twenty eleven theme mix up the css measurement units? I'm wondering why does WordPress's default theme mix up the css measurement units? For example: .one-column.singular #author-info { margin: 2.2em -8.8% 0; padding: 20px 8.8%;} Wouldn't be easier to understand and to work if all them were pixel based? Thanks
**Its just a css thing... while the distance from the top object is to remain permenant the distance from a side object is relative and those changes (sometimes) as the screen resulotion changes..** That prevents smaller screens from having a broken site. Anyhow thats the old way to go about it (in a matter of speaking) since "Responsive website design" is the modern way to control website fluidity...
stackexchange-wordpress
{ "answer_score": 2, "question_score": 3, "tags": "theme development, css, theme twenty eleven" }
Can a page_id and a post_id be same? Wordpress generates ID's for each page/post. Do pages in wordpress share the same ID column in the database as the posts? I mean, if a site has both posts and pages, can one or more page_ID's be same as some Post_ID's?
No, all posts, pages and other custom post types exist in the same table (`wp_posts`) and they all share the same ID column. The ID is unique to each entry regardless of its post type.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "posts, pages, id" }
How to load a jQuery script last? How to get this to load last? <script type="text/javascript"> jQuery(document).ready(function(){ jQuery("div.domTip_tipBody").mouseover(function(){ jQuery("#yyy a.tippy_link").css("background-color","yellow");});   jQuery("div.domTip_tipBody").mouseout(function(){ jQuery("#yyy a.tippy_link").css("background-color","red"); }); });   </script> It is running before "div.domTip_tipBody" is being run (which is generated by a shortcode) so nothing happens. I have tried: <script src="script.js" type="text/javascript" defer="defer"></script> in my header.php before </head> but it doesn't help. Have seen "window.onload =" but not sure how to apply it. Any insight is appreciated. Thanks
add_action('wp_footer','myscript_in_footer'); function myscript_in_footer(){ ?> <script type="text/javascript"> jQuery(document).ready(function(){ jQuery("div.domTip_tipBody").mouseover(function(){ jQuery("#yyy a.tippy_link").css("background-color","yellow");}); jQuery("div.domTip_tipBody").mouseout(function(){ jQuery("#yyy a.tippy_link").css("background-color","red"); }); }); </script> <?php }
stackexchange-wordpress
{ "answer_score": 0, "question_score": 2, "tags": "jquery, headers" }
Network Admin "You do not have sufficient permissions to access this page." I have had trouble logging into WP-Admin with my admin account. I have reset my password, and I can now log-in to WP-Admin, but cannot reach Network Admin (/wp-admin/network), instead receiving "You do not have sufficient permissions to access this page." What do I need to do to restore the permissions the account had before the password reset?
The easiest way to restore Super Admin privileges is to add a bit of code to your theme's `functions.php` file to add yourself back: include(ABSPATH . 'wp-admin/includes/ms.php'); $user = get_userdatabylogin('YOUR_USERNAME'); grant_super_admin($user->ID); Once your Super Admin privileges have been restored you can remove this code from your theme.
stackexchange-wordpress
{ "answer_score": 7, "question_score": 5, "tags": "permissions, password, network admin" }
How to make "more" or "continue reading" links on excerpts nofollow? I tried to make each one of my post excerpt's link to the full post "nofollow" like this: <a href="<?php the_permalink() ?>" rel="nofollow">&rarr; Continue Reading</a> However, that doesn't seem to work. I'm pretty new to WP / PHP, so what do I need to do?
In your theme's _functions.php_ : /* Returns a "Continue Reading" link for excerpts, with 'nofollow' set */ function your_theme_continue_reading_link() { return ' <a href="'. get_permalink() . '" rel="nofollow">' . '<span class="meta-nav">&rarr;</span> Continue reading</a>'; } /* Replaces "[...]" (appended to automatically generated excerpts) */ function your_theme_auto_excerpt_more( $more ) { return ' &hellip;' . your_theme_continue_reading_link(); } add_filter( 'excerpt_more', 'your_theme_auto_excerpt_more' );
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "php, nofollow" }
wp_query custom post type by taxonomy & standard post by taxonomy Anyone know how I can neatly combine a query to pull CPT by a custom taxonomy and also standard posts by taxonomy into same query to list all posts together on my home page? for example: $args = array( 'post_type' => array( 'artists', 'post' ), 'post_status' => 'publish', 'tag_artists' => 'home', // cpt custom taxonomy ## 'tag' => 'home', // standard post type taxonomy ## ); $query = new WP_Query( $args ); This is clearly wrong as it finds zero results..
here is the answer: $args = array( 'post_type' => array( 'artists', 'post' ), 'post_status' => 'publish', 'tax_query' => array( 'relation' => 'OR', array( 'taxonomy' => 'tag_artists', 'field' => 'slug', 'terms' => array( 'home' ) ), array( 'taxonomy' => 'post_tag', 'field' => 'slug', 'terms' => array( 'home' ) ) ) ); $query = new WP_Query( $args );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "custom post types, wp query" }
display metabox on front end (my-metabox-class) I would like to display metabox repeater fields on the frontend. Here is the code to setup the metabox repeater fields: $my_meta = new AT_Meta_Box($config); $repeater_fields[] = $my_meta->addText($prefix.'t_field_id',array('name'=> 'Title'),true); $repeater_fields[] = $my_meta->addText($prefix.'d_field_id',array('name'=> 'Description'),true); $repeater_fields[] = $my_meta->addText($prefix.'p_field_id',array('name'=> 'Price'),true); $repeater_fields[] = $my_meta->addImage($prefix.'i_field_id',array('name'=> 'Image'),true); $my_meta->addRepeaterBlock($prefix.'re_',array('inline' => true, 'name' => 'This is a Repeater Block','fields' => $repeater_fields)); $my_meta->Finish(); I tried to use this code: $title = get_post_meta(get_the_ID(),'mt_t_field_id',true); echo $title; Any advice?
Nice to see people using my class :) Anyway when you save a field in a repeater block , to access the data you need to use the repeater ID which in your case it's $repeater_data = get_post_meta(get_the_ID(),$prefix.'re_',true); and this returns an array of arrays with the id as key and value as value so you can loop over the array like this: foreach($repeater_data as $arr){ echo 'title: ' . $arr[$prefix.'t_field_id']; echo '<br />Description: ' . $arr[$prefix.'d_field_id']; echo '<br />Price: ' . $arr[$prefix.'p_field_id']; echo '<br />image: <img src="' . $arr[$prefix.'i_field_id']['url']">'; } to understand better how an image field is stored take a look at the **`class's wiki`** or the comments on **`this post`**
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "metabox" }
Static Front Page problem My theme uses the front-page.php file to display a number of items on the front page including a slideshow and some featured items. I have also designed it so the static front page as set in the wordpress settings is displayed **as an excerpt** within this template. I then planned on having a read more button so the full page could be viewed on it's own without the slideshow etc( i presumed using page.php ) but it appears I've outsmarted myself, as that static page seems to be destined to display using front-page.php according to the WP hierarchy. Can anyone suggest anything that might help me. What i need is some way to tell that page to open in page.php if it's accessed via the read more button.
I would recommend having **two static Pages** for this arrangement: 1. The static page to serve as the Placeholder for your site front page 2. The static page to hold the content you want to display as an excerpt on the front page Then, in `front-page.php`, you simply query static page 2 above, and output `post-excerpt` and a permalink. Once the permalink is clicked, the content from static page 2 is then rendered as per normal, via `page.php`. (If this is a distributed Theme, then you'll want to add a Theme option or other means by which to select the Page ID to query in `front-page.php`; otherwise, you can just make the ID static, hard-coded in the template file.)
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "theme development, templates, options, template hierarchy" }
Adding a div at the bottom of a sidebar I can't find a way to place a div at the bottom of a wordpress sidebar, after all the widgets are displayed. Though I can acheive this by tweaking the themes I need a way to do this programmatically. Please help..
You can use jQuery $('<div id="your_div"></div>').insertAfter('#sidebar_container_id'); Documentation
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "php, plugins" }
Use Post as Front Page Is there a way to use a post as the front page? I'd like to be able to call the latest post from a given custom post type, in a certain custom taxonomy and with a specific term and use this as the front page - similar to using a page as the front page, but using a post instead (showing comments, trackback, etc. too)?
1. You just need to modify the main query: // inside functions.php function wpse47667_intercept_main_query( $wp ) { // Modify the main query object $wp->query_vars['custom_tax_name'] = 'custom_term_slug'; return $wp; } add_filter( 'parse_request', 'wpse47667_intercept_main_query' ); 2. Then you have to replace `the_excerpt()` with `the_content()` inside your `index.php/home.php/front-page.php` template file, to show the full post instead of the excerpt.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "posts, frontpage" }
Add Category Taxonomy Support to Custom Post Type I'm writing some code that makes extensive use of custom post types- and I'm looking for a means of programatically adding a category to a defined custom post type, and then accessing its category ID. I had a poke around but I can't seem to find a robust means of achieving this - wp_create_category would be the obvious choice but of course this doesn't support custom post types.
if you need to pre-create some terms you can add the following into the init function that registers the taxonomy. it will create the term foo in the recordings taxonomy if (!term_exists( 'foo', 'recordings') ){ wp_insert_term( 'foo', 'recordings' ); })
stackexchange-wordpress
{ "answer_score": 4, "question_score": 6, "tags": "custom post types, categories" }
Showing a list of posts when homepage is custom I am developing a custom theme. I edited my home.php to show something custom. I also edited index.php to display a list of posts or other things. After this I can't get a list of all posts which was by default displayed at the home page. Which URL can I use to access the list of posts?
First, you need to familiarize yourself with the WordPress Template Hierarchy, so that you ensure that you are modifying the appropriate template file: * **Home** : _Blog Posts Index_ page; template file: `home.php` * **Front Page** : _Site Front Page_ ; template file: `front-page.php` I am assuming that you want to display a **static front page** , and to _display your blog posts index on a separate page_? If so: 1. Use the `front-page.php` template file to define the custom front-page markup 2. Use the `home.php` template file to define the markup for your blog posts index (or, omit entirely, and let the blog posts index simply fall back to `index.php`) 3. Create **two** static pages: one as the site front page placeholder, and one as the blog posts index placeholder 4. Set `Dashboard -> Settings -> Reading` appropriately
stackexchange-wordpress
{ "answer_score": 5, "question_score": 1, "tags": "theme development, homepage, blog, home url" }
Using pre_get_posts to set posts per page, how do I? I am trying to use pre_get_posts to set posts per page for a single term within a taxonomy. One thing that is throwing me off is setting the term to apply the pre_get_posts to. Here's my code: function filter_press_tax( $query ){ if( $query->query_vars['tax_query']['taxonomy'] == 'press' && $query->query_vars['tax_query']['terms'][0] == 'press' ): $query->query_vars['posts_per_page'] = 5; return; endif; }//end filter_press_tax I'm not quite understanding how to access the taxonomy and term in the $query. Yes the taxonomy and term have the same name. Is this a bad idea? I do not have a custom query set up on the taxonomy-press-press.php template for the 'tax_query' is this the problem? Any help is appreciated! Thanks
You're almost there mate. Try this though. <?php add_action('pre_get_posts', 'filter_press_tax'); function filter_press_tax( $query ){ if( $query->is_tax('press') && $query->has_term('press')): $query->set('posts_per_page', 5); return; endif; } ?> You can use any conditional tag or any argument that can be passed to `WP_Query` to test your condition or set a new value via `pre_get_posts`. Also try `$query->get('taxonomy')` / `$query->get('term')`. And check this for `$query`'s set and get methods.
stackexchange-wordpress
{ "answer_score": 15, "question_score": 5, "tags": "taxonomy, pre get posts" }
What is the difference between wp_register_sidebar_widget and register_widget? What's the difference between them and when should we use each one ? I'm using `wp_register_sidebar_widget` right now and it's working fine but I've seen a lot of tutorials online on how to create a widget using register_widget and a class, most of my widgets doesn't need options so should I stick to `wp_register_sidebar_widget` or should I use `register_widget` even if I don't have a form ? thanks in advance.
`wp_register_sidebar_widget()` is part of the _old_ widgets API. Sidebar widgets used to be built procedurally ... in a non-reusable fashion (i.e. you could only ever have one of each). `register_widget()` was introduced with the new Widgets API and takes an object/class as an input rather than actual widget parameters. WordPress can instantiate as many copies of this widget as you need, allowing you to have several instances of the exact same widget. You should be using individual widget classes and `register_widget()` even if your widget doesn't have an input form.
stackexchange-wordpress
{ "answer_score": 11, "question_score": 10, "tags": "theme development, functions, widgets" }
Is there any inherent difference between add_filter() and add_shortcode() for modifying [caption]? The context is the [caption] shortcode found in media.php which contains `img_caption_shortcode` img_caption_shortcode also includes these lines: $output = apply_filters('img_caption_shortcode', '', $attr, $content); if ( $output != '' ) return $output; I'm trying to manipulate the output the caption shortcode and it struck me that I could filter the function or I could add_shortcode to replace it - is there any difference? and if so what would are the tradeoffs? Many thanks in advance.
`add_shortcode()` may be overwritten, dependent upon at what point it is hooked, whereas you would have to `remove_filter()` to prevent the filter from executing. I think the way to go is to use `apply_filters()`, as that functionality is clearly put in place to do exactly what you're trying to do.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "shortcode, filters" }
Remove WordPress Toolbar buttons Is there anyway to remove the 'W' icon from the WordPress toolbar located at the top, when Authors login? I know that an author can uncheck an option for an individual user, but we need to do this for all users?
function mytheme_admin_bar_render() { global $wp_admin_bar; $wp_admin_bar->remove_menu('wp-logo'); } add_action( 'wp_before_admin_bar_render', 'mytheme_admin_bar_render' ); For specific user roles you can wrap the `add_action` in a conditional, something like if(current_user_can('editor')){ add_action( 'wp_before_admin_bar_render', 'mytheme_admin_bar_render' ); } <
stackexchange-wordpress
{ "answer_score": 7, "question_score": 5, "tags": "plugins, profiles, admin bar" }
Remove or Edit <dc:creator> in Feeds Would like to remove `<dc:creator>` or edit it to be a static value without editing core Wordpress files. Preferably as a function.
1. Copy `/wp-includes/feed-rss2.php` to your theme folder 2. Edit it and make whatever changes you desire (e.g. removing the line for `dc:creator`) 3. in your theme's `functions.php` file, add the following function: remove_all_actions( 'do_feed_rss2' ); function create_my_custom_feed() { load_template( TEMPLATEPATH . '/feed-rss2.php'); } add_action('do_feed_rss2', 'create_my_custom_feed', 10, 1); * * * **Edit by Otto** : While that will work, this would be a better way: function create_my_custom_feed() { load_template( TEMPLATEPATH . '/feed-rss2.php'); } add_feed('rss2', 'create_my_custom_feed'); The `add_feed()` function is smart, and will handle the actions and such for you. _Note_ : It will require a one-time use of `flush_rules()` to take effect.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 6, "tags": "rss, feed" }
How do I flush the rules after saving settings using the Settings API? I'm using the Settings API to allow the user to toggle the `has_archive` option on some custom post types. When the user turns archives on or off, I want to flush the rewrite rules. If I had written the saving function myself, I could just call `flush_rewrite_rules()` and be done with it, but the Settings API takes care of the saving for me. Is there a hook somewhere that I can use? ## Chosen Solution @Stephen Harris add_action('admin_init', 'my_plugin_register_settings'); function my_plugin_register_settings() { if (delete_transient('my_plugin_flush_rules')) flush_rewrite_rules(); register_setting('my_plugin', 'my_plugin_settings', 'my_plugin_sanitize'); // add_settings_section(), add_settings_field(),... } function my_plugin_sanitize($input) { set_transient('my_plugin_flush_rules', true); return $input; }
You simply need to visit the Settings > Permalink page (you don't have to do anything there) after saving the settings. > If I had written the saving function myself, I could just call flush_rewrite_rules() Not quite. `flush_rewrite_rules()` would have to be called after the custom post type is 'updated' to reflect the changes, that is, after you register it. So you would need to call it on the next page load, after the CPT is registered. You _could_ use a transient to trigger flush_rewrite_rules() on the next ( **and _only_ the next**) `init` (and after CPT is registered). To be clear, `flush_rewrite_rules()` is expensive and shouldn't be called regularly, this is why I suggest simply telling your plug-in users to visit the Settings > Permalink page after altering any permalink options - that way the rules get flushed only when its really needed.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 4, "tags": "hooks, settings api" }
Cleanest Way to Select Every Second Element in a Loop? What's the quickest and easiest way to select every second element in the loop? At the moment I'm using this strange method: <ul> <?php $k = 1; ?> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <li class="<?php if($k%2 == 0) echo 'last'; ?>"><?php the_content(); ?></li> <?php $k++; ?> <?php endwhile; ?> <?php endif; ?> </ul> Can't use nth-child since IE doesn't support it and CSS3 PIE isn't playing nice with my site at the moment.
I wouldn't consider that strange :). WordPress uses a similar method to apply the 'alternate' class to every other row in the tables on the admin page, something like: <ul> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <?php $class = (empty($class) ? 'class="alternate"' : '');?> <li <?php echo $class; ?> ><?php the_content(); ?></li> <?php endwhile; ?> <?php endif; ?> </ul>
stackexchange-wordpress
{ "answer_score": 6, "question_score": 5, "tags": "loop" }
What is the best way to provide plugin users with a way to customized the styles I'm working on a plugin to be release to the public, it is a very simple plugin that includes a single html element in the page html. I can do many things to allow users customize its appearance: 1\. Let them override a default CSS that is includes as a plugin configuration (on a management screen) 2\. Require that they modify their styles.css (not a very good idea for this plugin) And probably a fee more option 1 seems like the most user Friendly, since it allows any admin to modify the style without need of accessing code. But I wonder if there might be a better way? Is it possible to provide a default CSS file for the plugin that would be theme independent and would be editable through a management screen? The styling needs to persist regardless of chosen theme. Any thoughts?
Is it possible? Yes. # Option 1 Simply register and enqueue your default stylesheet. The theme stylesheet can then be used to override whatever styles you implemented. function register_my_styles() { wp_register_style( 'default-style', plugins_url('default.css', __FILE__) ); wp_enqueue_style( 'default-style' ); } add_action( 'wp_enqueue_scripts', 'register_my_styles' ); # Option 2 Register whatever custom options you need either on a specific plugin options page or using the WordPress Settings API. Then output these styles in a regular old script block in the theme header. function output_custom_scripts() { ?><style type="text/css"> <?php echo get_option( 'custom_css' ); ?> </style><?php } add_action( 'wp_head', 'output_custom_scripts' );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 3, "tags": "plugin development, themes, css, configuration" }
What is the etiquette on extending a plug-in I recently played with a plugin which I liked a lot, but felt it was missing something. So as first stage I went and wrote a tiny plugin (my first), that just added the needed feature - meaning, that the original plugin still had to be installed for something to work. Now I gave credit to the authors for doing most of the job, but I have to think of the future, what happens if they decided to stop developing that plugin or don't resolve issues regarding it. My plugin will stop working or will potentially become incompatible with future Wordpress versions. Would it be ethical for me to just avoid the issue alltogether by copying their code into mine and renaming the plugin functions? This of course causes other problems, but now they are my problem to resolve. What say you?
I'm assuming for now that the plugin is open source. If so ... # Send them an update Most devs appreciate contributions from the community. Contact the original authors and offer your code as a patch to add your new feature. # Reference the plugin Optionally, you can just hope that they keep developing the system and offer your smaller plugin as an extension. Just be sure to keep it up-to-date with a list of compatible WP versions _and_ the 3rd party plugin versions. # Fork Open source software is meant to be extended, adapted, and distributed. You have the right under most OS licenses to edit and redistribute the software so long as you follow a certain set of rules (i.e. maintaining original copyrights, releasing under a compatible license). I can't speak to specifics without knowing _which_ plugin you're using, but in the majority of cases forking the plugin and releasing your own version is 100% acceptable.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 6, "tags": "plugin development" }
Does the user_register change in multisite? I've created a function that automatically creates a new post for people when they register. It works great on a standard site but in multisite it stops working. I've spent hours trying to debug it. Is there a better hook to use than `user_register` in multisite?
There is the action hook **`wpmu_new_user`**. /* * Create a user. * * This function runs when a user self-registers as well as when * a Super Admin creates a new user. Hook to 'wpmu_new_user' for events * that should affect all new users, but only on Multisite (otherwise * use 'user_register').
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "user registration" }
highlight specific text in the content box This is an idea that came through my mind, and I would like to know if possible and how to approach it if so... I have my own wordpress framework that I use as based for all my projects, I manage the content position generated in the content box using shortcodes which respond to an especific div with a location... Said this, sometimes I find myself into a mess really hard to understand, for sample: [one_column] content [/one_column] [one_column] content [/one_column] [one_column] content [/one_column] [one_column] content [/one_column] when the among of text is big, is hard to find where the shortcodes are placed. So, is there any way to highlight the shortcode (like with a different color) into the content box? or maybe easier, is there any way to indent the content and keep that indent once I save or update the post? I would like to hear you opinion, Thanks in advanced. Kind Regards.
The only way I can think of doing this is with JavaScript to regex your parameter and apply a css style to them on the fly. Check out these jquery plugin for ideas: < <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "content" }
How should I best target dynamically served content? I am editing the 'Bizz' portfolio Wordpress theme( It includes custom post types for managing portfolio examples, the highlights on the homepage, etc. I want to style the background color displayed behind each 'highlights' heading with a different color, but since they're served dynamically, I'm not sure how I should target each h2. Would it be best to attach a unique class to each of the three headings through the php, or try to target them through CSS selectors? And how would I best do that? My major concern in using CSS selectors would be backward compatibility, I dont know that I want to bulk up the page with extra bootstraps. How should I go about it? Thanks!
I think it depends on whether you want it to be unique for each of the four "highlighted" project columns on the homepage, or whether you want each "highlighted project" to be different. Does that make sense? E.g. if you just want each of the four project "columns" on the homepage to look different then I'd use CSS to achieve this : nth-of-type perhaps. But if you wanted Project A (when highlighted on the homepage) to have a unique background colour regardless of what column it appears in, then Id use PHP to add the post->ID as a class in addition to portfolio-item and then use CSS to style that.
stackexchange-wordpress
{ "answer_score": -1, "question_score": 2, "tags": "php, themes, css" }
W3 Total Cache Minification: way to revert back? W3 Total Cache Minification: after adding all my js files in the minification settings, what if something screws up? Is is possible to revert back to the original un-minified files? Thanks.
Just turn off minification. It's not a destructive process, your original files remain untouched.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "cache, plugin w3 total cache" }
Commenting system for WordPress Hi I am thinking of changing from the default WordPress commenting system to Disqus or LiveFyre. What are the biggest advantages of such a change, and maybe possible pitfalls I should look out for. Thanks.
When you use Disqus you are in a way giving away the control to that company. The module is indeed very nicely built, you can access Disqus admin section from within your WP admin panel, but like I said; you are handing over the "root control" to Disqus.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "comments" }
Remove action from shortcode There is add_action() function inside function which is callback for add_shortcode(). Any idea how to remove this action with the help of custom plugin? Should I hook to any action which is called later then add_shortcode() function? I do not want to removing and re-adding shortcode, because there is huge function beyond it. Simple example: function test_shortcode() { ... other code ... add_action( 'some_hook', 'custom_function'); ... other code ... } add_action( 'wp_head', 'setup_theme' ); function setup_theme() { ... other code... add_shortcode( 'test', 'test_shortcode' ); ... other code ... } I need to remove custom_function() from this shortcode. Thank you for your help...
OK, I found a way. Function add_shortcode is called for the_content filter with priority 11 (after wpautop). So, to remove custom_function() has to be done with the help of this filter (also with priority 11). Solution? add_filter( 'the_content', 'unhook_custom_function', 11 ); function unhook_custom_function( $content ) { remove_action( 'some_hook', 'custom_function' ); return $content; } Works well for me. Thank you all for ideas!
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "actions, shortcode" }
Managing Backups: Space Issues I recently reached 95% full storage on my GMail. Approximately 60% of this was, in fact, email backups from Wordpress' "WP-DB-Backup" plugin on 10+ sites that I manage. (I get a scheduled daily backup of the whole database.) There must be a better way to manage my backups. Ideally, if I can somehow automatically delete all but the most recent backup (whatever the solution is), that would be best. Sure, I can manually do this in GMail, but it's tedious and error-prone. Is there a better way to do this, or a better way to manage WP backups without worrying about HD space? GMail doesn't look like it's a good solution.
You can use a plugin like **`backwpup`** that lets you: * Store backup to Folder * Store backup to FTP Server * Store backup to Amazon S3 * Store backup to Google Storage * Store backup to Microsoft Azure (Blob) * Store backup to RackSpaceCloud * Store backup to DropBox **(free)** * Store backup to SugarSync **(free)** and manage the number of backup copies to store which means for example you set the number to be 5 and when you reach backup number 6 the first back will be deleted for you.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "backup" }
Is it possible to integrate Wordpress *posts* and social media (Facebook, Google+, Twitter)? Is there a plugin available that will automatically post an excerpt of a blog post (perhaps up to the more tag) to specified social media groups/pages. So, for example, on posting an excerpt would be posted with a 'Read more' link to a user-defined Facebook group, G+ page and, possibly, twitter feed? If not, is there a method for automating this process? Or is copy>paste the only realistic option? (I know that Dsiqus provides the ability to link comments and social media but this functionality doesn't extend to posts, as I understand it.)
Search for plugins: < and < and < All require applications be built at each service for different levels of interaction with a Wordpress site, including automatic excerpt posting (except for G+), tweeting and linking.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 3, "tags": "plugins, plugin recommendation, facebook, google plus" }
Passing a variable via wp_head and then calling it on the page As my question suggests I'm having difficulty creating a variable in the header, via functions.php and wp_head, and then calling that variable further down the page. For example, in functions.php add_action( 'wp_footer', 'add_ran_var' ); function add_ran_var () { $random_variable = "1"; } And before the </head> tag include <?php wp_head(); ?> in header.php The problem arises if i try to call $random_variable later on in the page. It returns nothing. <?php echo $random_variable; ?> Could anyone please shed some light as to why this does not work? Has it something to do with the order the different files (header.php, functions.php) are called? Thanks in advance to anyone who can offer me some advice on the above. Cheers Noel
Before you use your `$random_variable` for the first time you need to globalize it , something like: global $random_variable; then next time or any time you want to access it just call globalize it again and it will be available like this: global $random_variable; //do stuff with it
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "functions, headers, wp head" }
Why is `add_meta_box` not working? I'm trying to add some meta fields to a WPSC product using the following code: /** * data callback */ function abc_callback($object, $box) { echo 'callback executed!'; } /** * add custom fields */ function abc_load_post($post_id) { add_meta_box('abc_post_id', 'abc', 'abc_callback', 'post', 'normal', 'default', array()); } add_action('load-post.php', 'abc_load_post', 10, 2); add_action('load-post-new.php', 'abc_load_post', 10, 2); The `abc_load_post` function gets called fine but nothing actually appears on the product editing page (i.e. `/wp-admin/post.php`) Can someone explain what I'm doing wrong?
I can see 2 problems with your code. You seem to want that meta box to appear on product pages, but you actually add it to the post type and not the product post type. The other problem is the hook you attach your function to. Try this: add_action( 'add_meta_boxes_{post_type}', 'abc_load_post' ); Substitute {post_type} with whatever post type you actually want to target, e.g. product, post or page. The fourth argument for add_meta_box() is the post type, btw, which you have set to 'post'.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 2, "tags": "metabox, actions" }
Remind a user about their account if they have not used it for 6 months I have a website working with a user registration/login system all working also. I wish to automatically send all users an email that have not used their account for 6 months. I have an idea, but just wondered if there would be a better/more convenient solution. Because this will be done in PHP, I guess this requires a cron job, which isnt a problem as I have done many of them before. Wordpress just doesnt seem to store the last time a user visits my site (to my knowledge). I then thought I could just store in the database (manually) the last time a user visits the site, and run a comparison to the current date in a PHP cron file. Has anyone got a better suggestion? Or even a plugin to do it for me :p Thanks!
Take a look at the Transients API. It's meant to store data temporary. Note, that this doesn't replace a cron job, as it needs "Action" on the site. So if the site isn't requested, where you set/alter/delete a Transient, then nothing happens.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "cron, user registration" }
Add a new post status in the post progression I run a site with about 30 authors and 3 editors. Authors submit posts for review, and editors schedule or publish them. It would be useful to have another post status of "Editing" between Pending Review and Scheduled/Published. I realize there's a warning when someone else is editing a post, and that's probably significant enough, but I'd like to explore adding a new status level. So, current post progression: Draft --> Pending Review --> Scheduled/Published Desired post progression: Draft --> Pending Review --> Under Review --> Scheduled/Published Thoughts?
I recommend you install the Editflow plugin, it lets you add arbitrary post statuses so that you can customise your workflow as you wish < !enter image description here
stackexchange-wordpress
{ "answer_score": 3, "question_score": 5, "tags": "posts, admin, workflow" }
How to hide plugin options for editors via functions.php I've read the entry **_Best Collection of Code for your functions.php file_** , it really help me a lot. I only got a question, **is there a way to hide some plugins options (in their respective administrations), just like the way you hide the widgets at the dashboard?**. This because I have to let the editor manage some parts of the plugin, but not all (for example, in a slider, he/she must edit the images to display, but not the dimensions of the slider).
This should be easiest way, just add the line to wp-config.php, this will disable plugin and theme editor, both. `define('DISALLOW_FILE_EDIT',true);` If you want to add codes into theme's function, the code should work for you. function ra_block_tp_edit( $caps, $cap ) { if($cap == 'edit_plugins' ) $caps[] = 'do_not_allow'; return $caps; } add_filter( 'map_meta_cap', 'ra_block_tp_edit', 10, 3 ); Best of luck.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, admin, permissions, capabilities, user roles" }
Issue with sidebar widgets not showing when I do custom queries I'm having issues with this. I have 2 while loops, each getting different custom post types. They both work fine, except, my sidebar content i.e. widgets, is not appearing. I think this is because I am not running the default query. My two queries are: query_posts('post_type=offered'); while (have_posts()) : the_post(); ?> ....content endwhile; and $wanted_query = new WP_Query('post_type=wanted'); while ($wanted_query->have_posts()) : $wanted_query->the_post(); ....content endwhile; However, when I try to combine them as below, I get the sidebar content but no my posts! global $query_string; query_posts( $query_string . '&post_type=offered' );
When you do a query, you change the environment, specifically the current post and query objects. To reset things back to how they were before the query loop you should: query_posts('post_type=offered'); if(have_posts(){ while (have_posts()) : the_post(); ?> ....content endwhile; } wp_reset_query(); // reset query!!!! or $wanted_query = new WP_Query('post_type=wanted'); if($wantedquery->have_posts()){ while ($wanted_query->have_posts()) : $wanted_query->the_post(); ....content endwhile; } wp_reset_postdata(); etc, also, check if you have posts before doing the loop, rather than going straight into the while loop.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "query posts, sidebar" }
Different number of posts in each category I have categories driven site. I have different template for each category. I would like to set different number of posts – **different for each category**. Plus I would like to add proper previous and next links in each category. for example in this `category-1.php` I want 4 posts per page: <?php query_posts('showposts=4'); ?> <a href="<?=next_posts()?>"> PREVIOUS </a> <a href="<?=previous_posts()?>"> NEXT </a> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> ... <?php endwhile; endif; ?> but in this example `next_posts()` and `previous_posts()` doesn't work.
As @StephenHarris pointed out there's also the `pre_get_posts` filter. function hwl_home_pagesize( $query ) { if ( is_category( 9 ) ) { // If you want "posts per page" $query->query_vars['posts_per_page'] = 1; return; } if ( is_category( 'movie' ) ) { // If you want "showposts" $query->query_vars['showposts'] = 50; return; } } add_action( 'pre_get_posts', 'hwl_home_pagesize', 1 ); Example altered from Codex example.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 5, "tags": "posts, categories, cms, codex, limit" }
Easiest way to have closed comments on a custom post type My site has several different kinds of post types. One of these is Discussions. The site is completely open and public, but my client has asked that I provide a space where only certain members can have discussions/post comments. Basically, I want only members/authors/editors/whoevers of my site to see/post new Discussions. I've explored using bbpress and other forum options, but they're all too complicated. Is it even possible in WordPress to have only registered users see/post to a Discussions post type? Thanks Terry
## Template Tags for the rescue 1. Only logged in users: is_user_logged_in() 2. Only logged in users that have a certain capability assigned to their role current_user_can($capability) 3. Only logged in users that have a specific role assigned current_user_has_role($role) 4. Only logged in users that have a specific capability assigned (to their role) on a specific blog current_user_can_for_blog($blog_id, $capability)
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, private" }
Is there any function available to echo current user's profile url? As of now i'm using this code to echo user's profile url. <?php echo esc_url( home_url( '/' ) ); ?>user/<?php echo $current_user->user_login ?>"><?php echo $current_user->user_login ?></a> This link uses author base as "user". So when i change author base this link will be broken. IS there any function available like `current_user_profile_link()` ?
## Choosing the right template As your "User Profile"-Page is something completely custom and **not** the admin UI user profile page, I'd suggest to take the uthor posts page instead: get_author_link( true, get_current_user_id() ); Then modify this template. ## Pretty URls No need to go outside the WP template hierarchy. If you want something like `~/user`, then use the `Rewrite API`. * * * ## ( Update ) `get_author_link()` This function has been deprecated. Use `get_author_posts_url()` instead. **Example** get_author_posts_url( get_current_user_id() ); <
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "users, author, profiles" }
How to enable the <br /> tag in Wordpress posts and pages i can't understand why so simple feature are disabled by Wordpress Team. I want have line breaking with "br" tag. On one wordpress forum was idea to modificate editor.js (in wp-admin/js) and formating.php (in wp-includes) files. < I was tryed to do this, but 0 good results.
First things first, modifying core files is extremely frowned upon you will have to make these changes with every upgrade and they can lead to security and other problems. I'm pretty sure there is a plugin that will allow this. I did a simple search and here are a few to try: < <
stackexchange-wordpress
{ "answer_score": 2, "question_score": 4, "tags": "visual editor, post editor, wp autop, line breaks" }
How to insert pictures without hard coded dimensions? How can I insert pictures into a post without any hard coded dimensions (e.g. `<img src="" alt="" />` instead of `<img src="" alt="" width="" height="" />`)? I don't want my users to switch to the HTML tab and remove the parameters by themselves, so I was wondering if there is any filter I can use to achieve this? Note: I'm already inserting them in "Full size".
I found a solution in the meantime: `wp_get_attachment_image_src()` to get the `src` for the images. I think it ends up by being the easiest solution and it requires no filters.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 8, "tags": "images, responsive" }
frontend user with custom profile pages i am building a website where the frontend users can register and they need to have custom profile pages - not the standard WordPress backend pages that the admin sees. There they can see their profile (image, name, email, ...) and change it, as well as some site specific pages like: statistics, severals lists, ... . is there a plugin for this? or if not could you please point me to some documentation or other links that might help? Thanks.
Have you tried using BuddyPress? BuddyPress allows all these thing, and has many other features ( though things can be turned on and off if it's too much )
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "front end, profiles, user registration" }
I used the Buddypress Message Compose to send a site wide email to all members wasnt sent tho I used the Buddypress Message Compose to send a site wide email to all members wasnt sent though. Where would I look to see why messages were not delivered to all site members of my buddypress wp site? Can I configure this to use smpt instead? I researched this some and found others have had similar problems with the "send to all" from the buddypress message compose screen but couldn't find solutions. I am thinking it may have something to do with the wp config file and how emails configured? Thanks
The way the feature works is by posting the message on the screen, not in the members inbox, and it requires the template tag: <?php bp_message_get_notices(); ?> So wherever you put the tag, the message will appear there. In the default buddypress theme, it shows up when you activate a message and the user is logged in, right below the log out link in the sidebar login form. To send inbox messages through buddypress, you can search for the Mass Messaging plugin.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "buddypress, email" }
Q&A lite plugin comments I am trying out the Q&A lite plugin from WPMU. It looks great except for one thing. It looks like users can only ask and answer question, not make comments on them. This effectively makes a conversation between two users very short. One question, one answer, that's it, excepting answers from other users of course, but there can be no conversation as such, which I find puzzling as to how effective it could be. Can anyone tell me if I am using it wrong? I think not but if I am I would like to know, otherwise can anyone recommend something similar.
We had a similar question which received a nice amount of answers and the main issue with the plugin you linked was that it had no comments for the questions and answers and if you look at the comments you will see that both types (questions and answers) support comments you only need to display them.
stackexchange-wordpress
{ "answer_score": 0, "question_score": -1, "tags": "plugins, third party applications" }
How can I get more out of `$post` in an `add_action` callback? I have the following action callback set up: function abc_save_post($post_id, $post) { // do stuff echo '<pre>'.print_r($post,true).'</pre>'; } add_action('save_post', 'abc_save_post', 10, 2); The thing is that `$post` is a very trimmed down version of `$_POST` and is missing lots of data that I want to get at. How can I get more data into `$post`?
Simply use the post ID, provided by `$post_id` (and stored at `$post->ID`) to use the various functions WordPress provides to get any extra data related to that post (`get_the_terms`,`get_post_meta` etc). Performance wise you suffer no loss by using these functions as opposed to trying to force more data into the `$post` object (probably the reverse in fact), since WordPress caches data related to posts (such as taxonomy terms, post meta,...)
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "actions" }
reverse next/prev page order I think the way wordpress display previous and next posts is basically non sense, with next posts on the left side, and older posts on the right side. I am using the code <?php posts_nav_link() ?> is there a way to reverse such order?
This is because it is, by default, done as 'previous page' on the left, and 'next page' on the right. Posts appear in reverse chronological order, with the latest post first, so 'next page' means going back in time. So in terms of pages it makes sense, in terms of chronology it doesn't. Anyway... this should work: <div class="navigation"> <div class="alignleft"><?php next_posts_link('&laquo; Older Entries','') ?></div> <div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div> </div>
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "navigation" }
How to Loop with the final result formatted differently? I need to list post_title's in this specific format (note the last title in the list **must not** have a comma) "post_title","post_title","post_title" I thought a mini-loop might work. Here's what I'm using <?php query_posts('cat=0$posts_per_page=-1'); // query to show all posts independant from what is in the center; if (have_posts()) : while (have_posts()) : the_post(); ?> '<?php the_title(); ?>', <?php endwhile; endif; wp_reset_query(); ?>]"> But I need the final post_title to have no trailing comma?
I'm not sure of the context for this, but `query_posts` probably isn't what you want to use. (See this answer). ( _Untested_ ). I would use get_posts: $posts = get_posts(array( 'numberposts'=>-1, 'category'=>0 )); And then use `wp_list_pluck` to get the titles: $post_titles = wp_list_pluck($posts,'post_title'); $post_titles = array_map('esc_html',$post_titles); Finally, the php `implode` function an list them with commas: echo '"'.implode('","',$post_titles).'"';
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "loop" }
wp_upload_dir how to get just the directory name . I imagine that this would be a breeze for some - but I'm having difficulty getting just the upload's directory name - not the full path - I've gotten this far: $uploads = wp_upload_dir(); $upload_path = $uploads['baseurl']; // now how to get just the directory name? anyone have any ideas? thanks for sharing your experience. . .
This is what you get back from the function: Array ( [path] => C:\development\xampp\htdocs\example.com/content/uploads/2012/04 [url] => [subdir] => /2012/04 [basedir] => C:\~\example.com/content/uploads [baseurl] => [error] => ) So you can get the (as @OneTrickPony pointed out), folder/directory name with echo wp_basename( $uploads['baseurl'] ); If you're running multisite and you defined the constant `UPLOADS`, then you access it from `UPLOADS` or `BLOGUPLOADDIR`. **EDIT** For multisites, you would get something like this: Array ( [path] => /var/www/example.com/public_html/wp-content/uploads/sites/2/2016/12, [url] => [subdir] => /2016/12, [basedir] => /var/www/example.com/public_html/wp-content/uploads/sites/2, [baseurl] => [error] => , ) Where the "2" after `sites` is the blog's ID
stackexchange-wordpress
{ "answer_score": 31, "question_score": 22, "tags": "uploads" }
Proper Network Activation problem has been fixed in wp 3.3.1 or not? @scribu opened a core trac ticket here for Proper Network Activation problem in multisite. It seems like its fixed in wp 3.1. But scribu was saying it doesn't fixed in wp 3.1. So he released a plugin for proper network activation. I'm using wordpress multisite. So can anyone tell me whether this problem fixed in wp3.3.1 or not?
In short: No, it hasn't been fixed - You should use the plugin instead. In Detail: Activation hooks should work for the main site properly. For subsites (or as Nacin pointed out: for all sites), you should use a proper upgrade routine. _Not that I double that 1)._ 1) Note to myself: When a core dev says that core internals are _lame_ , then this should tell me something. Not shure what exactly, but I'll think about it.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "multisite" }
post/page content I am trying to insert a post/page into one of my themes files and it won't display shortcodes or PHP. I have created a page called home in the wordpress admin-paned and inserted into my code the following: <div id="home_page"> <!-- echos the content from the page "home" id:43 --> <?php $home_id = 43; $home_page = get_page( $home_id ); ?> <?php echo $home_page->post_content; ?> </div> <!-- end #home_page --> and non of the shortcodes that I have in the page work. I installed a `php in post or page` and tried using php and it doesn't work. when I insert echo do_shortcode('[youtube_sc url= directly into the code it works. does anyone know y this happens? thank you.
You need to apply the filter `the_content` e.g.: <?php echo apply_filters('the_content',$home_page->post_content); ?> Also, you don't need custom shortcodes for youtube, just put the URL in the content (but not a hyperlink), and it'll be swapped out for a youtube player at runtime. No plugins or extra code needed thanks to oembed.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "posts, pages, shortcode, code" }
Combining the_excerpt with the_content I have some html: <div class="container"> <p class="accent">The first paragraph...</p> <p>The rest of the article...</p> </div> I'd like to put "the_excerpt" in the first paragraph (with a special colour / font size) but then have the following text be "normal". Is there a way to **subtract** the_excerpt from the_content so the section "The rest of the article" does not repeat the excerpt?
The key is to use **user-defined excerpts** , rather than auto-generated excerpts. For example: <div <?php post_class(); ?>> <?php // If post has defined excerpt, output it here if ( has_excerpt() ) { ?> <div class="first-paragraph-excerpt"> <?php the_excerpt(); ?> </div> <?php } // Now output the content the_content(); ?> </div> <!-- .post --> You'll need to adapt to your needs, but this will output a div with the Excerpt, if it exists, and then output the content.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "loop, the content, excerpt" }
I put my blog on a subpage, how do I get page title? I've got my blog setup on a subpage (not the front page) and I'm using the template file `home.php`, how can I get the contents from the page editor onto this subpage? If I change the title of the page it changes in the nav menu, but how can I get this to display on the page? (i.e. as the `<h1>` header)
Untested, but try: <?php echo get_the_title( get_option( 'page_for_posts' ) ); ?> But it's _somewhat_ hackish. Really, the `page_on_front` and `page_for_posts` are intended to be nothing more than _placeholders_ for the site front page and blog posts index page.
stackexchange-wordpress
{ "answer_score": 8, "question_score": 4, "tags": "templates, page template, blog, blog page" }
Remove Tag from theme support I would remove Tag capability from classic Post type, can I use `remove_theme_support( $feature );` and how to do this ? Thanks in advance
You can do it with something like this: add_action( 'init', 'wpse48017_remove_tags' ); function wpse48017_remove_tags() { global $wp_taxonomies; $tax = 'post_tag'; // this may be wrong, I never remember the names on the defaults if( taxonomy_exists( $tax ) ) unset( $wp_taxonomies[$tax] ); } There was a move to get a function implemented but that hasn't hit yet.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 3, "tags": "add theme support" }
writing a plugin, how to disable the comment form altogether? I'm writing a protected-page plugin and want to disable comments on protected pages. I'm usually hooking into `the_content` but that's not enough for comments. I got into `comments_array` to block the existing comments, but how do I block `comments_template`?
You can control whether comments appear by filtering the `comments_open()` function. Here is an example from the WordPress codex: add_filter( 'comments_open', 'my_comments_open', 10, 2 ); function my_comments_open( $open, $post_id ) { $post = get_post( $post_id ); if ( 'page' == $post->post_type ) $open = false; return $open; }
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "comments" }
How to get post category title within the loop? I'm stuck in a rather simple task: to get the category title for the current post, within the loop, to be used in the function (not to be automatically printed). Any ideas?
The function `get_the_category()` returns an array of category objects. To get the name of the first category, use this: $categories = get_the_category(); $cat_name = $categories[0]->cat_name; For a list of the properties of the category object, see the documentation on `get_the_category()`
stackexchange-wordpress
{ "answer_score": 6, "question_score": 1, "tags": "categories, title" }
Getting a role based on a localized role name I use the following code to get the Administrator role $admin = get_role('administrator'); This works fine, but on a different WordPress language setup, this code breaks. For example, in French it should be $admin = get_role('adminstrateur'); Any cross-language solution?
Just guessing, but maybe: $admin = get_role( __( 'administrator' ) ); If you're trying to make sure that WP translates the string for a specific locale, `__()` will return the translated string. So if `get_role('administrator')` works and on a French setup `get_role('administrateur')` would work, then the above code snippet should do what you need.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "user roles" }
RSS feeds and wordpress? I'm working on my first wordpresss website and I've really never worked with RSS feeds. However my friend that I'm doing a website for wants it in there. so I guess I'm in a crash course learning session with google to learn all I can about RSS feeds. I was hoping to find a plugin that just allowed the visitor to subscribe to the websites blog but they are all pretty ugly, or not what I want. !enter image description here I'm hoping to have an email field that I can style like the way I have designed it here. Or even something like the way this website has it done Are there any good plugins and articles to read up for a beginner wordpress theme developer to learn this RSS feed information?
As you develop WP theme, I would mention that you need to enable automatic-feed-links by adding following function call to your functions.php file: add_theme_support( 'automatic-feed-links' ); After it RSS links fill be added automatically to head of your site. The best practice is to add this call in function for `after_setup_theme` hook handling: function my_theme_setup() { add_theme_support( 'automatic-feed-links' ); } add_action( 'after_setup_theme', 'my_theme_setup' );
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "rss" }
Custom Permalink Structure for Pages & Posts I'd like to create a permalink structure that works in the following way: Pages - < Posts - < / How would I do so? Thank you
Go to "Settings" -> "Permalink" page and set custom structure for permalinks equals to `/news/%postname%`.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "posts, permalinks, pages" }
What is the cleanest way to extract custom variables from a post At the moment I am doing something like the following from inside the main loop; $custom_values = get_post_custom_values('tenderfields'); $custom_values = unserialize($custom_values[0]); $custom_values = $custom_values[0]; Then accessing them with `$custom_values['my-custom-value']` This works fine but feels a little clunky, it feels like something there is probably already an internal call for that I am just missing? I have looked through the docs and couldn't find anything.
If you always need **all** of post meta at once this is the way to do it. To access post meta for specific key use `get_post_meta()` that will retrieve value(s) and unserialize if needed.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "custom field" }
Alphabetical search Is is possible to create an alphabetical search like so: A | B | C | D | etc Each letter is a link so when clicked it would show all the posts starting with "A" or "B" etc etc. If so, how could I do it?
Yes. Do a SQL query for posts using `LIKE 'x%'`, where `x` is your letter. Here's a simple example: global $wpdb, $post; $letter = 'a'; // or $_GET['letter']... $query = "SELECT * FROM {$wpdb->posts} WHERE post_name LIKE %s"; $query = $wpdb->prepare($query, $letter.'%'); $results = $wpdb->get_results($query); // note that variable name must be $post, // because you need to override stupid wp globals... foreach($results as $post){ setup_postdata($post); // the usual loop functions go here the_title(); } wp_reset_postdata();
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "search" }
wp_verify_nonce vs check_admin_referer What is the difference, which one should I use? I know that wp_verify_nonce checks the time limit, and check_admin_referer I think calls wp_verify_nonce as well as checking for an admin url segment, but I'm a bit confused on which one I should use and when. Thanks for the clarity.
I _thought_ that `check_admin_referer` checked the nonce (it does call `wp_verify_nonce`, **and** the referring url. After digging into the core code I realised that it did not do this. Thinking it was a bug I reported it, and Ryan Boren replied with the following: > Actually, if the nonce is valid the referrer should not be checked. The unreliability of referrers is one of the reasons that nonces are used. Nonces replace referrer checking entirely. The only time we check the referrer is when handling the -1 backward compatibility condition. -1 means that someone is not using nonces so we fall back to referrer checking. This usage is now very rare. check_admin_referer() is badly named now that it almost never does referrer checking. It would be better named something like check_nonce(), but we keep it as is for back compat and old times sake. So there is in fact there is no difference.
stackexchange-wordpress
{ "answer_score": 35, "question_score": 28, "tags": "admin, security, nonce" }
Using custom page templates with plugin I'm developing a plugin. This plugin creating a new post type and displaying these posts in a custom template. For example it's a event calendar plugin. This plugin creating a new post type 'event '. Users adding new events from wp - admin, like normal blog posts. And users creating a new page with 'Event Calendar ' page template. But for enabling Event Calendar page template, users have to copy eventcalendar.php from plugin's dir to their template's dir. Last step (copying file) is really hard for some users. Is it possible to call custom page template from plugin dir?
I second Tom's answer, however in the interest of answering your question, have a look at this question using the `template_include` filter.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "custom post types, plugin development, page template" }