INSTRUCTION
stringlengths 11
999
| RESPONSE
stringlengths 0
999
| SOURCE
stringlengths 16
38
| METADATA
dict |
---|---|---|---|
I am not able to enable jQuery in theme settings
I have tried to - enable `Use jQuery` & then save changes.
But after saving changes, checkmark `Use jQuery` automatically unchecks itself.
I am not sure whats going on. Please help me here.
!enter image description here | From the comments fo @OneTrickPony, I came to know that,
`Mystique hasn't been updated for a long time, but a major update is going to be released these days, and most likely this won't happen in the new version...`
So, I conclude that issue is coming from the Theme itself. ( Not sure, but from the comments of @Milo & @OneTrickPony )
So, I uninstalled & removed `mystique` theme & at last I installed other theme. I know this is not the exact solution. But I had no option. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "wp admin, jquery, options"
} |
Can I Create a Static-Content Site With WordPress?
Hi I'm evaluating wordpress to implement a rather static website ( that now uses static html that I think could be advantageous to do with wordpress since it would make updates and administration easier. Do you agree with me that it's possible to implement these quite simple webpages with wordpress? I started a project to do this at < not getting very long since I didn't see how to upload a logo image etc but I'm sure that it can do all or most of what is required. | Yes of course you can recreate that site using WordPress. You gain the benefit of managing all the pages from the WordPress admin, and gain consistency across all the pages due to the templated nature of WordPress pages.
You can start by finding or creating a very basic theme that mimics the look of the existing site. Then just copy your content into WordPress Pages (copy and paste.) You can even make it look like the pages are HTML by adding the .html extension to your permalink structure. You can redirect traffic to your old pages to the new pages, if the names are different.
So long at the host that hosts www.eddaconsult.se supports PHP 5.2.4 and MySQL 5.0, you can run WordPress without a problem. Here are the requirements for WordPress version 3.2.
Without a doubt, you can do this project with WordPress. | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 0,
"tags": "static website"
} |
Internal linking search box not working - WP 3.2
I'm developing on a local install of WP 3.2 and noticed that the search box inside the insert/edit link dialog is not working (Tiny MCE link button in the visual editor).
Has anyone else experienced this / know what might be causing it? The search indicator just spins without returning any results when I type in keywords which I know to be good. | Looks like this was caused by the WP-o-Matic plugin which my client was using. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "links"
} |
List custom taxonomy terms
I am trying to display all of the terms for a custom taxonomy(`characters`), the taxonomy is related to a custom post type(`books`).
What I would like to do is display all of the terms for `characters`, so say for instance I have two `books`, and I add three `characters` to each `book`, I would like all six characters to display.
I would only like to get the names, not links, or in list form, if I could get a set of objects or an array that would be preferable.
Thank you. | I believe what you are looking for is the get_terms function. I found it looking at the code for wp_tag_cloud, here is the source of the function. This little snippet should get you what you are wanting.
$terms = get_terms("characters");
if ( empty( $tags ) || is_wp_error( $tags ) )
return;
foreach ( $terms as $term ) {
echo $term->name;
} | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "custom post types, custom taxonomy, taxonomy, terms"
} |
Some questions about WPMU
I just activated wordpress multisite in my site.
I have few questions.
1) WPMU and wordpress multisite both are same?
2) I created a network in my site. I created like site1.mydomain.com, site2.mydomain.com etc. Is it possible to make my subdomains posts summary appear in my main domain?
3) Is it possible to make users access all subdomains with single registration?
Thanks | 1) WordPress MultiUser (WPMU) was the term used before WP3. WPMS is for version 3 and newer.
2) Subsite posts appearing on the main site is built into BuddyPress. You will need to install BP to your multisite setup for this to work.
3) There are several plugins that achieve this either through a) a single user database shared across all sites, or b) duplication of users with differing user permissions per site. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": -1,
"tags": "multisite"
} |
Why doesn't my simple the_title filter get applied?
I have added the code below to an active plugin, but it's having no effect on my posts.
add_filter( ‘the_title’, ‘myfunction’);
function myfunction($title) {
return "Why won't this work?" . $title;
}
What am I missing here?
The post templates are definitely using the_title(), and the theme is normal (wp_head(), etc), and there are no conditionals surrounding the function in the plugin that would make it not run. I have also tried adding different priority in the add_filter function, from -9999 to 9999, to no effect. | Try changing this:
add_filter( ‘the_title’, ‘myfunction’);
to this:
add_filter( 'the_title', 'myfunction' );
(If this is indeed your problem it is likely an issue of copy/pasting code from a tutorial with curly quotes in place of standard single-quote marks.)
p.s. prefix your function name with your Plugin slug. "`myfunction`" is far too generic. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "plugin development, title, filters"
} |
Is it necessary to translate WordPress key terms when localizing a plugin
In translating a plugin, how should "WordPress" key terms be handled? For instance, should the following need translations or should they be left as is:
* Taxonomy
* Custom Post Type
* Taxonomy Term
* Plugin
Since these terms all have very specific meanings and are documented within the Codex using these English words, would it make more sense to just leave them in English as opposed to translating them? I almost think of these words as proper nouns that would not be changed when translated. | These terms are not proper nouns and are translated in localized versions of WP Core.
Therefore, they should also be translated in plugins.
Ideally, you could use them without a textdomain and WP would load it's own translation. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "plugins, localization"
} |
How to Remove all Instances of edit_post_link
Can someone please assist with how to remove from my theme, whilst in author mode, the edit_post_link (Edit link), throughout all my pages. Which php files in the Twenty Eleven theme (WordPress v3.2) do I need to comment out to no longer display this edit link?
I realise that you only see this during author mode but would like to know how to remove altogether.
Thanks. | It's the `edit_post_link()` function. You'll find lines like the following, that you need to comment out:
// from /twentyeleven/content-intro.php
edit_post_link( __( 'Edit', 'twentyeleven' ), '<span class="edit-link">', '</span>' ); | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 7,
"tags": "php, pages, theme twenty eleven"
} |
display public excerpt for private post
Thank you in advanced. I know there are plugins that can do this, but I am looking for a simple solution for my function file. I would like to display the excerpt for all posts with the more tag for public visitors, even for private posts. | I've not tested this, but you should be able to complete this task by placing the following code in your template above the loop.
query_posts(
array(
'post_status' => array(
'published',
'private'
)
)
);
This should allow for published and private posts to be displayed in that template. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "functions, excerpt, private"
} |
Need help fixing sql syntax error after WP 3.2 upgrade
I'm using a plugin that failed after upgrade to wp3.2.
The error log shows:
> WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 for `query SELECT post_id, meta_value, post_status FROM bxxoai_postmeta LEFT JOIN bxxoai_posts ON post_id=bxxoai_posts.ID WHERE post_status='publish' AND meta_key='wpfp_favorites' AND meta_value > 0 ORDER BY ROUND(meta_value) DESC LIMIT 0, made by require, require_once, include, get_header, locate_template, load_template, require_once, get_sidebar, locate_template, load_template, require_once, wpfp_widget_view, wpfp_list_most_favorited`
mysql version I used is 5.0.92-community
I'm clueless with database, can anyone please teach or help explain to me what needed to be done to fix this? | I ran into this as well... I am using the SQL query, but not the wpfp_list_most_favorited() function, so this may or may not work for you, but worth a shot. Try updating the SQL query in wp-favorite-posts.php (around line 206) from:
$query = "SELECT post_id, meta_value, post_status FROM $wpdb->postmeta";
To:
$query = "SELECT post_id, meta_value, meta_key, post_status FROM $wpdb->postmeta";
Hope this helps! | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "database, upgrade"
} |
Custom settings disappear during database migration?
I've noticed a problem that pops up occasionally when moving a WP install from one place to another (usually the same server.)
I copy all the files to their new location, get a mysql dump, update all references to the old paths in the sql file, then import it to the new database.
Everything always works just fine apart from custom settings that have been added using register_setting. I can still see them in the database, but WP completely ignores them, and they need to be added again in the backend.
Is there something obvious I'm overlooking here? I can post up the code I'm using to build the custom settings panels if necessary...
Cheers. | Mostly a dupe: Why is my database import losing text widget data?
Doing a search and replace on an sql dump breaks URLs in the serialized data of widgets and theme options. See the link above for better ways to change URLs when moving WP sites.
Use Database Search and Replace Script in PHP | interconnect/it to find/replace in the database via correctly serializing data. | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 5,
"tags": "menus, options, migration"
} |
How do WordPress veterans deal with the issues of upgrading WordPress?
Sometimes upgrading WP is catastrophic: critical plugins don't work any more (and new compatible versions don't exist yet).
What do the WP veterans do about it? Do they upgrade WP after the boring work of backing up everything (and the horrible, awful perspective of having to reinstall the previous version after a potential catastrophe) or do they just never upgrade WP? | "the boring work of backup"...
Backups may be boring, but they are essential and gives you a fallback position in case things go wrong. Without backups, you're essentially playing Russian roulette with your site. It doesn't even take very long, and reverting isn't horrible or awful, it's pretty easy.
WP veterans take backups, test upgrades on non-production servers, and when they're happy do the upgrade. Most 'ordinary' people don't have access to multiple servers or even local development environments, in which case the best way to mitigate your risk is to have a backup
If you have access to the command line, then doing a complete backup is as easy as:
1. `tar czvf yoursite_backup.tar.gz /path/to/your/wordpress`
2. `mysqldump -u <username> -p <database name> > mysqlbackup.sql`
Reverting is as easy as unarchiving your WP backup to your WP directory and importing the MySQL dump into your database. | stackexchange-wordpress | {
"answer_score": 10,
"question_score": 3,
"tags": "upgrade, backup"
} |
How to get a page array and category array going at the same time?
I'm using the code below to add a logo in the header of certain pages and I'm wodering if there a way to add the logo(sublogo.jpg) to certain categories as well as "page-one", "page-two" and so on?
<div id="header-logo" onclick="location.href='<?php bloginfo('url'); ?>'" style="cursor: pointer;" >
<?php if (is_page(array('page-one', 'page-two', 'page-three','page-four'))) $logo_image = 'subLogo.jpg';
else $logo_image = 'mainLogo.jpg';?>
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/<?php echo $logo_image;?>" alt="<?php bloginfo('name'); ?>" />
</div>
Thanks, | extend this line:
<?php if (is_page(array('page-one', 'page-two', 'page-three','page-four'))) $logo_image = 'subLogo.jpg';
with
|| is_category(array('cat-1', 'cat-2'))
so you get, for example:
<?php if (is_page(array('page-one', 'page-two', 'page-three','page-four')) || is_category(array('cat-1', 'cat-2')) ) $logo_image = 'subLogo.jpg';
< | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "array"
} |
Redirecting when changing custom post type slugs?
I changed the name of two of my custom post types. The original slugs for them did not properly reflect the post type. So I need to redirect requests for posts beginning with `designer_lingerie` (the old post type slug) to just `designer`. All of the posts are the same just the post type slug has changed.
I am sure I'll need to use `.htaccess` but am unsure of what to tell it to change. Basically what URL should I use to do this? The WordPress pretty URL or the default URL? | All you need to do is add a line like:
RewriteRule ^aboutus$ /about-us [R=301,L]
In to your .htaccess file. The old url should go between the ^ and $ and then new url after the slash. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "custom post types, url rewriting, redirect"
} |
Taxonomies image
I'm currently creating a theme and I would like to associate an image to one of my taxonomies.
I'm already able to add some fields and I now want to add a file input which'll be handle by Wordpress upload function.
So, 2 questions : \- Is it possible to add an enctype to the taxonomy form ? \- Is it possible to use the Wordpress upload function at this point ?
Thanks for your answers.
Cyril | Michael Fields built the perfect plugin for this:
< | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "custom taxonomy, wp admin, admin, uploads, images"
} |
is_archive() returns false on the archives page
I've followed the official documentation to create my archives page: <
It works fine exept that "is_archive() returns false when I'm viewing this page.
Any idea ? | Because an "archives" _Page_ is not an _archive index_ of blog _Posts_ , but rather a _Page_.
An "archives" page is simply a custom Page template, which applies to a static Page.
The `is_archive()` conditional returns true if an _archive index_ is being displayed. An archive index page displays _Posts_ , not static _Pages_.
**EDIT**
Instead of using `if ( is_archive() )`, try using `if ( is_page( 'archives' ) )` (assuming you've named your static Page _Archives_ ).
Alternately, you could use `if ( is_page_template( 'archives.php' ) )` (assuming you've named your _template file_ as `archives.php`). | stackexchange-wordpress | {
"answer_score": 6,
"question_score": 4,
"tags": "archives"
} |
Wordpress Shortcodes - Optional Styles
i'm creating some custom shortcodes for my wordpress theme. Shortcodes are by nature optional on pages/posts, but may contain css, js or other files.
My question is, how can i enqueue css styles ONLY IF a particular shortcode has been used ? I would not want to load everything for no reason. | The general process for this is:
1. Create a function, hooked into `wp_enqueue_scripts`
2. Inside your function, cycle through the Loop, looking for your shortcode string
3. If found, call `wp_enqueue_style( 'my_custom_style' )`
4. Rewind the Loop, by calling `<?php rewind_posts(); ?>` | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "theme development, shortcode"
} |
Limit archive widget results
Is there a way to limit the amount of months shown in the Archive widget? I don't want to use a drop-down list (I can manually add a drop down in my footer so people can get the full archive). I'm currently showing 19 months in my Archive list, and want to limit it to 7. I know you can do this manually, but that would mess up my theme, so I wanted to do this with the Archive widget. | I would use the PHP Code Widget from Otto and then simply put this in the widget to limit the archives to 7 months:
`<ul><?php wp_get_archives('type=monthly&limit=7'); ?></ul>`
(Give the widget a title like Archives if you want, and remove the default WordPress Archive widget.)
Function Reference/wp get archives | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "widgets, archives"
} |
Comment_form and GD Star Rating
I'm finding GD Star Ratings a bit complex to work with. I'm using the comment_form function to generate a custom "review" form on a custom post type. At the top of the form, I want reviewers to leave their rating.
I am _guessing_ that I want to hook into the "comment_form_top" action with one of the gd star ratings functions. Am I thinking the right direction? If so, do any of you have a code sample I could refer to? I'm having a hard time finding much in terms of documentation.
Any ideas and suggestions are welcomed - Thank you! | Got it! The key was a custom callback on wp_list_comments. Here's the snippet of code I used within my comments:
<?php if (defined("STARRATING_INSTALLED")) : ?>
<div class="rating" style="float: right">
<?php wp_gdsr_comment_integrate_standard_result(get_comment_ID()); ?>
</div>
<?php endif; ?> | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "comment form, plugin gd star rating"
} |
How do the pros code up a WordPress theme? Locally? Through FTP?
Up until now, I've been building my WordPress sites by transferring files through FTP. This can sometimes get really slow (time it takes to upload the file, Firebug slows to a crawl, etc.) and I was wondering how all the pros do it. I heard about installing something locally on your computer and building everything there? I'm new to this whole concept of building a site locally and would appreciate some guidance—mostly to speed up my development time. Thanks in advance. | 1. Local web server is a must, it's pretty much generic web server stack (Apache, MySQL, PHP plus other bits) only running on your local computer.
2. Deployment depends on how you manage your code:
* just resides on your computer - you will need to sync it to remote server in some way (FTP, SFTP, etc), any decent software for such is smart enough to transfer changed files only;
* resides in version control - you commit local code to repository, then you can either pull to remote site from that repository (or simply make commits and uploads independently).
See Software for WordPress Theme and Plugin Development? for specific software titles. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "php, ftp, localhost"
} |
How do I minify '@import' css files with wp-minify?
I am trying to use wp-minify to minify my js/css on the fly. I can get the 'direct' css files to be minified, but I can't seem to get wp-minify to minify the 'linked' css files. My theme is a child theme off of twenty-ten, so my child theme's styles.css gets minified, but not twenty-ten's styles file. | `@import` prevents "parallel" downloads. I'd not suggest to use it in case you want to minify css files. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "css, optimization"
} |
WordPress/jQuery pagination plugin for multiple lists
I have 3 shortcodes. Each of them will be displaying a list.
PS> the lists do NOT contain wordpress posts/pages.
Is there any WordPress plugin that can achieve the purpose?
OR
Please suggest me a jQuery plugin that uses Ajax to fetch subsequent paged data and can work with my scenario. | I've used **jpaging** before which is simple ,easy and highly customizable. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "plugin recommendation, jquery, pagination, ajax, jquery ui"
} |
creating a foreign key like relationship with custom post types
I am currently building a website, that is heavily reliant on custom post types, 2 of my custom post types are "Clients" and "Case Studies", now what I am wanting is a way to create a dropdown in the "Case Studies" custom post type so that I can select from the Clients that have already been added to the site? Is this possible, I assume it would be similar creating a relationship in database, and then pulling in the clients from the clients and table and placing them in a `<select>`. | You can create relationships between posts / pages with the Posts 2 Posts plugin. (more info on the wiki)
You could then create a connexion between `Case Studies` and `Clients`, and associate them accordingly.
For clarity, you should ask your second question in a separate question, as it is not related to the title of this thread. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "custom post types, loop"
} |
user_can() not working for comment authors
I'm trying to do some capability checks on comment authors using the user_can() function, but for some reason it isn't working at all.
I have a custom capability setup with the Role Manager plugin called "read_citizen".
My check looks like this:
if(user_can($commentAuthor->user_id, 'read_citizen') {
//do stuff here
}
I have confirmed that the $commentAuthor object is set correctly.
Ideas? | Ok, found the answer. It was just an oversight on my part.
I was using the wrong variable name for the USER ID. In the $wpdb comment object, the user ID is stored as `user_id`, but in the USER object, the ID is stored just as `ID`.
So, by using `if ( user_can($commentAuthor->ID, 'read_citizen') )`, it all works. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "user roles, capabilities"
} |
Overriding Gallery Margin
Continuing the build on a free theme. Working on the gallery CSS. Wordpress automatically adds a left margin to the gallery. Example: < So, how do I get rid of that nasty margin?
/* Gallery */
.gallery {
margin:30px auto auto;
text-align:center
}
.gallery-item {
float:left;
margin-top:10px;
text-align:center;
width:33%
}
.gallery img {
border:1px solid #E6E6E6!important;
margin-bottom:27px;
padding:5px
}
.gallery img:active {
margin:1px 0 0
}
.gallery-caption {
display:none;
font-size:.8em;
margin-left:0
}
.gal_img {
margin:20px auto 0!important;
text-align:center
}
.gal_caption p {
font-size:1.3em!important;
font-weight:700;
text-align:center;
font-family:Arial, Helvetica, sans-serif!important
}
.gal_description p {
font-size:1.1em!important;
text-align:center
} | The simplest method is to remove the WordPress-injected inline style definitions, so that you can control style completely via the Theme:
/**
* Remove default gallery shortcode inline styles
*/
add_filter( 'use_default_gallery_style', '__return_false' );
Note that this will remove ALL WordPress-injected gallery CSS definitions, so you may need to port some of the original style definitions into your stylesheet. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 3,
"tags": "css"
} |
Register Custom Post Type from Plugin
I'm trying to register a CPT from a plugin upon activation but seem to have hit a wall... Anyone see anything im missing? I don't get any errors but the CPT doesn't show up in the dashboard links....
function ctg_cpt_init() {
register_post_type( 'ctg_questions',
array(
'labels' => array(
'name' => __( 'Questions' ),
'singular_name' => __( 'Question' )
),
'public' => true,
'has_archive' => true,
'rewrite' => array( 'slug' => 'questions' )
)
);
}
add_action( 'init', 'ctg_cpt_init' );
function ctg_rewrite_flush() {
ctg_cpt_init();
flush_rewrite_rules();
}
register_activation_hook( __FILE__, 'ctg_rewrite_flush' );
Thanks, | Pull the CPT registration functionality out of the _Plugin activation_ hook, so that it can fire at `init`, where you want it to.
The Plugin activation hook is a one-time only hook; you need your CPT to fire _every time_ at the `init` hook, not just once. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 2,
"tags": "plugins, custom post types"
} |
User Without Email?
When creating a user in Wordpress an email address is required for that user. The website I'm working on requires that users remain anonymous (it's part of a research study) and I'd consider email to be an identifying piece of data. Users will be added manually, so email is not required to confirm accounts or prevent spam sign-ups.
Am I going to have to provide a fake email address for each account, or is there a way to leave this field blank? | It's possible, just not so easily via the Users page without some hackery.
The WordPress Function wp_create_user will let you insert users without email addresses, so a little custom plugin to accept a login name and password, and a call to `wp_insert_user` or `wp_update_user` should work for you. Unfortunately I don't have time to code it up for you, but perhaps this will point you in a direction.
$userdata = array ('user_login' => 'someuser', 'user_pass' => 'swordfish');
$new_user_id = wp_update_user( $userdata );
**Update for people looking for a solution with the REST-API:** Unfortunately, this is not possible by the rest-api. the email is required there. see: < | stackexchange-wordpress | {
"answer_score": 9,
"question_score": 8,
"tags": "email, user registration"
} |
"Error establishing a database connection" - Intermittent error on GoDaddy
After transferring a working WordPress site to GoDaddy hosting, we've begun getting "Error establishing a database connection" errors on all pages- first intermittently, and now consistently. It's strange because it worked most of the time, at least at the beginning, but now errors all the time. This is all within the first few hours of our install- I'm wondering if this might be a database caching issue on WordPress? Is there a cache to clear?
Thanks- | -First, try contacting the hosting provider if the database server is online / if they have any other problem at their end, or they made any changes to your account, or if there are any limitations/restrictions, etc .
* double check your wp-config.php file settings for the database name, database username and database password. This is where most errors occur.
-Then check that you don't need to change the database host from "localhost" to something else. You can get that info from your hosting provider.
-Check you have actually created a database with the same database name as is in your wp-config.php file.
-Last, but not least, if all that information is correct your database probably has a problem with it, and you may need to contact your hosting provider.
There are also many threads on this topic on WP forums: < | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "database, errors, hosting"
} |
How do I retain url parameters the entire time a user browses my site?
We have customers that come from other sites and I would like to retain a url parameter /?lead=openeye throughout the time that they're browsing. That way when they fill out a form I can capture the lead for sales.
How do I retain url parameters the entire time they're browsing the site.
**Update..**
I've began using a combination of sessions and cookies to accomidate this. It sort of works but doesn't seem to stick for more than a few seconds between pages.
In the header
<?php
$lead = $_GET['lead']; $_SESSION['lead'] = $lead;
$url = parse_url(get_bloginfo('url'));
setcookie("lead", $lead, 0, $url['path'], $url['host']); (set)
?>
To test
<?php
echo ($_COOKIE['lead']); // Lead Cookie
?> | Better Answer:
`session_start(); $lead = $_GET['lead']; $_SESSION['lead'] = $lead;`
Then, create an additional field on the form, with the input hidden. For the value, I would echo out the $_SESSION, with a name that is easy to grab (lead works). then, wherever the form is processed, just add a line to grab the lead, and do with it what you want. – | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "url rewriting, domain, site url, parameter"
} |
How to alter the text of the post "Excerpt" box label in WordPress post editor?
My theme gives the site owner the option of using each post's "Excerpt" field to fill in the "meta description" tag for each page.
It would be helpful if I can filter the text label and description text that appears on the default Excerpt input control when viewed inside the post editor.
Does a filter or hook exist for this?
Alternately, I suppose I could use jQuery to do something via the DOM. | there is a filter hook you can use and it is `gettext` here:
add_filter( 'gettext', 'wpse22764_gettext', 10, 2 );
function wpse22764_gettext( $translation, $original )
{
if ( 'Excerpt' == $original ) {
return 'My Excerpt label';
}else{
$pos = strpos($original, 'Excerpts are optional hand-crafted summaries of your');
if ($pos !== false) {
return 'My Excerpt description';
}
}
return $translation;
} | stackexchange-wordpress | {
"answer_score": 12,
"question_score": 4,
"tags": "theme development, jquery"
} |
Divide Menu into Separate Menus and Display them Side by Side
I'm having problems saving a large menu. I keep getting a 500 Internal Server Error. I'm using WP 3.1. I use a HostGator dedicated Linux server and the Superb theme.
I have a menu with 4 main headings each with dropdown menus. Is it possible to divide my menu into "4 menus" and display them side by side? The Superb theme has one menu area. Is this possible? If so, how can I do that?
Thank you.
-Laxmidi | I found a work around. I used the Gecka Submenu Pro plugin. (No, they didn't pay me to post).
Thank you. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "menus"
} |
How can I force users to a particular subdomain to log in for MU (Multisite)?
I have a Multi-Site installation of Wordpress, with multiple subdomains, but only one of the subdomains has an SSL certificate.
The domains are such:
www.example.com
blog1.example.com
blog2.example.com
secure.example.com
`secure.example.com` is the subdomain which has a SSL cert installed.
If someone types in `blog1.example.com/wp-admin/dashboard.php`, how can I force them to `secure.example.com/wp-admin` and then after they log in redirect them back to `blog1.example.com/wp-admin/dashboard.php`? | I would recommend using Peters Login Redirect to redirect users after login I have used it before and works well.
You could redirect users to the secure area by adding the below to your .htaccess file :
Redirect 301 blog1.example.com/wp-admin/dashboard.php secure.example.com/wp-admin | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "plugins, multisite, admin, login, ssl"
} |
Get taxonomy name of current post
Hierarchical taxonomy of custom post type 'projects' > 'projects_category'.
Two example 'projects_category' hierarchies would be:
> Big Corporates > 1st Company Name > A Post Title
>
> Small Business > 2nd Company Name > Another Post Title
I can get **'1st Company Name'** with the following:
<?php $terms = get_the_terms($post->ID, 'projects_category');foreach($terms as $term){echo $term->name;} ?>
How can I display 'Big Corporates' or 'Small Business' as appropriate in single.php ? | I've marked up anu's answer and get_ancestors explanation, however this is how I solved it:
<?php
$terms = wp_get_object_terms($post->ID, 'projects_category', array('orderby' => 'term_id', 'order' => 'ASC') );
if ( !empty( $terms ) ) :
$project = array();
foreach ( $terms as $term ) {
$project[] = $term->name;
}
echo '<h1>'.$project[0].'</h1>';
echo '<h2>'.$project[1].'</h2>';
endif;
?> | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 3,
"tags": "custom taxonomy, terms, hierarchical, single"
} |
Style the text before <!--more--> in single.php
I'd like to style differently the content before the link, but in single.php.
To be more specific, all my posts on the homepage only have a summary, and the rest of the text is cut thanks to the use of the more tag. So when I click on "read more" I see the complete post, starting with the summary we previously seen on the homepage. I'd like to differentiate this summary from the rest of the text, adding it some bold for example, to show to the user what he as already read.
Unfortunately I think this is not possible. Is it ? | using: <
and the $strip_teaser parameter: <
in single.php, replace `<?php the_content(); ?>` with:
<?php if( strpos(get_the_content(), '<span id="more-') ) : ?>
<div class="before-more">
<?php global $more; $more=0; the_content(''); $more=1; ?>
</div>
<?php endif; ?>
<?php the_content('', true); ?> | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 4,
"tags": "read more, css"
} |
how to have custom post template including custom write panels for the users to post
I would like to have a separate custom page where the logged in users can post their content. Add post title, add content, add check boxes, image/file uploads,
Is there any way to do so? | Maybe _scribu_ 's Front end Editor would be an easy way to update your website if your client finds the WP admin to be " _confusing and difficult_ ".
But also bare in mind that the admin is customizable through admin themes, as well as various scripts and plugins. To cite only one plugin, try Adminimize, it will allow you to remove a lot of unnecessary stuff from the interface. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "custom field, custom write panel"
} |
Execute script only on certain admin pages
To solve this problem i've used this in my js file:
var location = String(window.location);
//only runs in post.php and post-new.php
if(location.search('post.php') != -1 || location.search('post-new.php') != -1 )
{
}
But it's does not seem like i solid solution. Are there any other way? | You can use this in your `functions.php` :
function add_admin_scripts( $hook ) {
if ( $hook == 'post-new.php' ) {
wp_enqueue_script( 'myscript', get_bloginfo('template_directory').'/js/myscript.js' );
}
}
add_action('admin_enqueue_scripts','add_admin_scripts',10,1); | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 1,
"tags": "wp admin, wp enqueue script"
} |
Suggestion for Calendar of Events Plugin
I am searching for a plugin with the following properties, any suggestions would be appreciated:
* All events should able to be organised either by date or subject, searchable by visiting users and should include the capability to auto-expire.
* Each event should include a general description, venue details (date / time / area etc) and related images or videos.
* Users must be able to subscribe to an email notification mechanism which informs them about upcoming events.
* Calendar must also provide an approval workflow process prior the publishing of an event. | I'll give various types of calendar's, you choose any one of them as your needs. Sample Calendar. I think some combination is too good. :) | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 3,
"tags": "calendar"
} |
Ability to download only after email supplied
I would like to have a page with downloadable items like PDFs, but I would like the user to be required to insert email details before being able to download the files, although he would be able to view the files available even before providing the email address.
The system must also ask only once for the email, and then maybe keep a cookie so that it won't ask for each download requested.
Is there a plugin or code hack available for this? Thanks | I spent a long time looking. The best today seems to be < or if you want something more complex, < | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 2,
"tags": "email"
} |
Remove adjacent_posts_rel_link under 3.2?
I'm trying to remove the adjacent_posts_rel_link links under WP3.2, i.e. remove these from wp_head:
<link rel='prev' title='blah blah' href=' />
<link rel='next' title='blah blah' href=' />
and this function used to work under 3.1:
function remove_header_info() {
remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0);
}
add_action('init', 'remove_header_info');
But doesn't under 3.2. Anyone know or know how to find the new action to remove the links?
**Edit 7/15/11:** the change is `adjacent_posts_rel_link_wp_head` | Answer: the change in 3.2 is from `adjacent_posts_rel_link` to `adjacent_posts_rel_link_wp_head` | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "functions, wp head"
} |
How to properly sanitize strings for update_option()
I've tried to import an option value via update_options($name, $value) where $value has special characters (like apostrophe's for example) and I've noticed that the apostrophe gets stripped out of the text before it reaches the database.
What is the suggested sanitization of strings prior to sending them to update_options()? | Try `esc_html( $string )` (Codex ref), which among other things encodes single- and double-quotes.
For further reference, see the Data Validation entry in the Codex. | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 5,
"tags": "plugin development, options"
} |
Where do I put my add_action(... and add_filter(... and do I need to remove them?
I'm working on creating a plugin out of some custom code I use a lot, in hopes that other people find it useful too.
It works, so yay! but...
**Here's my question:**
I feel like I'm missing some puzzle pieces in my understanding of the system.
What happens to all the code I add and hook everywhere after I deactivate my plugin?
In my main .php file, when is the code that's not in a function being executed? Only at install? Then what is the purpose of `register_activation_hook( __FILE__,'install_method');` ?
If I put `add_action` and `add_filter` in my main php file, do I have to remove them at uninstall? (For example, I know that if I `add_option('option', '0', '', 'yes');` during install I have to `delete_option('option');` at uninstall.)
In some tutorial, they told me to put `if ( is_admin() ) {}` around my code, is this necessary? | filters and actions are added with _every request_. when you disable a plugin, they immediately disappear, because they only exist in your plugin code. this is how you're able to selectively add them on a per-request basis. you only need to remove filters or actions if you don't want them to run in the current request.
`is_admin()` is a check if the admin pages are being displayed, and should wrap things only for admin pages. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 0,
"tags": "plugin development, actions"
} |
wordpress how to query wp_options table
I need to make an SQL call to find all records in wp_options matching a select statement. How do I query the table?
My script already has these resources called...
require_once('../../../wp-blog-header.php');
require_once('../../../wp-admin/includes/file.php'); | All of database querying is handled by global `$wpdb` object. So when you load WP core you have acess to it and all its methods for queries. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "plugin development, options"
} |
CSS not pulling in for jQuery UI dialog
I want to add a jQuery dialog modal to a form page. When the dialog box is triggered I see the the text content but with no CSS. I'm pulling in the jquery in the functions.php for the page:
wp_enqueue_script('jquery-ui-dialog');
The jquery css (jquery-ui-dialog.css) is under my wp-includes/css directory. I tried adding
wp_enqueue_style('jquery-ui-dialog');
but it not work. Does anybody know the proper way to enable jQuery Dialog. | There is no `jquery-ui-dialog` style defined in WordPress Out of the box, you need to ue the stylesheets manually, when i needed to enqueue the jQuery-UI style i pulled it from google api CDN
wp_enqueue_style('jquery-style', '
but you can enqueue a local copy if you want like this:
wp_enqueue_style( 'myStylesheet', WP_PLUGIN_URL . '/path/stylesheet.css' ); | stackexchange-wordpress | {
"answer_score": 8,
"question_score": 9,
"tags": "jquery"
} |
A better code for no post format?
As suggested on this site, I am using this code to style an excerpt if no post format is selected/if it is a standard post.
<?php
$format = get_post_format();
if ( false === $format )
{
echo 'This is a default post';
the_excerpt();
}
?>
However, it seems there must be a better way to include it with one PHP statement... the rest of which follows this pattern:
if ( has_post_format( 'video' )) {
?>
A VIDEO POST
<?php the_content();
}
if ( has_post_format( 'audio' )) {
?>
AN AUDIO POST
<?php the_content();
}
Anybody know how to include the original code in this same if statement? If, then... | I'm not sure I understand. Do you just want to join all the if-statements together? If that's the case you could use elseif, like so:
<?php
$format = get_post_format();
if ( false === $format ) {
echo 'This is a default post';
the_excerpt();
} elseif ( has_post_format( 'video' )) { ?>
A VIDEO POST
<?php the_content();
} elseif ( has_post_format( 'audio' )) { ?>
AN AUDIO POST
<?php the_content();
}
?> | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "posts, php, post formats"
} |
How would I create a different permalink structure for pages and posts?
Right now I have pages like "about", "resources", etc and the urls are /about and /resources with a custom permalink structure as /%postname%. For "news" section it's the posts and it's at /news and that's great. The problem is I want the new stories to be /news/the-name-of-the-story not /the-name-of-the-story. Can that be accomplished in the wp admin area? Or is that a custom .htaccess trick? Also, news is in categories and /category/category-name lists the posts in that category and the story for those should be at /category/category-name/the-name-of-the-story. Is this even possible? | The custom permalink field on the settings->permalink screen _only_ applies to Posts. Not to Pages.
WordPress Pages always live at the "top" of the URL tree. /about /whatever /etc. Posts live wherever the custom permalink string defines them to be.
So, in your case, your permalinks custom structure would be "/news/%postname%/" and would not affect your Pages permalinks of "/about" and "/resources".
For instance, to put all Posts under the sub-directory "/blog", your permalinks custom structure would be "/blog/%postname%/". | stackexchange-wordpress | {
"answer_score": 14,
"question_score": 6,
"tags": "permalinks"
} |
Wordpress loop not working on blog.php page
Well, i'm creating a wordpress theme, but i can't get wordpress loop to work correctly for some reason. This code works fine in index.php :
<?php
if (have_posts()) :
while (have_posts()) :
the_post();
var_dump($post);
endwhile;
endif;
?>
But, it does not work in my blog.php page(it's not a template, it's actually a shortcode). The shortcode works correctly for sure. But when the above code is executed it just prints NULL. If i try to grab the_content, the page loops indefinitely.
Any idea why this can be happening ? | Within your blog.php file you need to declare `<?php wp_head(); ?>` without this the loop will not work and only so many items within `$post` will be available to you. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "theme development"
} |
How To Remove The Author(s) From Certain Posts
There are certain posts on the website I'm developing, that don't need the author(s) by-line. (such as press releases)
Is there any method, that allows me to remove the author (and co-authors) for certain posts? | Thanks to mike23's suggestion, I solved my problem with conditional tags.
* * *
Just insert the following in the author area of `single.php`, `archive.php` and any other page template that displays an author.
<?php if ( has_tag('press-releases') ) {
echo '';
} else {
echo 'by '; the_author_posts_link();
}
?>
Using the above code, you can remove the author name on all posts tagged `press-releases`.
All posts without the tag `press-releases` will retain their author name. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 2,
"tags": "author, conditional tags"
} |
Widget textarea input gets formatted
I've built a small widget for my website
It has a couple of inputs, and a `<textarea>` among others.
Whenever someone inputs to the textarea it adds a tab at the begining
and changes every ' to \'
After a couple of times I save the same input,
I just get sentences that were
> It's nice
to
> It\\\\\\\'s nice
the code for the Textrea:
<textarea rows="5" cols="40" id="cat_<?php echo $i ?>_text" name="cat_<?php echo $i ?>_text">
<?php echo $text ?>
</textarea>
Any ideas? | Try stripslashes to remove the backslash.
echo stripslashes( $text );
This is going to replace one slash per slashes group only though, you should first reset all the contents that have multiple slashes.
I guess the tab at the beginning is due to the fact that you jump a line before echoing the text. Try this instead :
<textarea rows="5" cols="40" id="cat_<?php echo $i ?>_text" name="cat_<?php echo $i ?>_text"><?php echo stripslashes( $text ); ?></textarea> | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "widgets"
} |
Calling static method in the Widget Class
I have a widget
class Xwidget extends WP_Widget{
function cron_addB(){}
}
I want to run a cron job that calls that function from outside the class
function xxx_cron_activation() { ;
if ( !wp_next_scheduled( 'xxx_followers' ) ) {
wp_schedule_event(time(), 'hourly', 'xxx_followers');
}
}
add_action('wp', 'xxx_cron_activation');
add_action('xxx_followers',array('Xwidget',"cron_addB"));
Cron is being triggered but the function is not being executed | Try this instead:
$gloabl $myxclass;
$myxclass = new Xwidget();
add_action( 'xxx_followers', array(&$myxclass, "cron_addB" ) );
or
add_action('xxx_followers', "init_xclass_and_cron");
function init_xclass_and_cron() {
$myxclass = new Xwidget();
$myxclass->cron_addB();
} | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 4,
"tags": "widgets, cron"
} |
Plugin for automatic database backup?
Is there a reliable plugin that I could use to automatically backup the WP database? **It's really important that it's just the database and not the files.**
I'd like it to automatically download a copy of the database and store it on my computer in a specified file.
Is there one out there that could do this? | BackWPup has a lot of flexibility in timing, what to backup (down to the DB table level), and it can store to DropBox which would put it on your computer. | stackexchange-wordpress | {
"answer_score": 7,
"question_score": 3,
"tags": "plugins, backup"
} |
Proper Way to Modify Plugin
What is the best way to modify a plugin? I frequently want to make small changes to one or two functions within a large plugin. This is easily done, but I have to use comments to mark my changes and modify the plugin again after an update. Ideally I'd like to leave the plugin alone and make my changes elsewhere, much like we do with themes and child themes. Can I make a plugin that requires the parent plugin and will override it? | IMHO, the best approach is either to fork the Plugin to maintain your changes, or else submit patches to the Plugin developer, to have your changes made a part of the original Plugin.
Creating a "Child Plugin" really isn't easy. The "Child Theme" concept really applies to the _template files_ that get used, moreso than the Theme functions (and in fact, the `functions.php` file from both Parent and Child get loaded, which _does_ cause problems for improperly coded `functions.php` files in either the Child or Parent Theme). | stackexchange-wordpress | {
"answer_score": 9,
"question_score": 23,
"tags": "plugins, customization"
} |
Wordpress thumbnail settings change
I have a very large Wordpress image bank (over 600 images, all in use...!) and a new development will mean that i would like to change some of the thumbnail settings.
I have at the moment
set_post_thumbnail_size( 75, 75, true );
In the functions, which of course means that the thumbnail is cropped to fit. I would like to change this so that the thumbnail is scaled, rather than cropped
set_post_thumbnail_size( 75, 75);
But will this change the current images i have? If not, is there a way of doing this?
Thanks! | The Regenerate Thumbnails plugin will go through your media library and re crop all your images. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 1,
"tags": "post thumbnails"
} |
get_the_term_list() wanting to loop through the returned values
I have a custom post type, I am echoing out my custom taxonomies in my template by doing the following, `get_the_term_list( get_the_ID(), 'work', '<li>', "", '</li>')` , this currently returns "Design", what I am wanting to do, is the following, for the first value that it is found I want to do the following,
`<li><a href="the taxonomies link"> Find out more about Taxonomy Name</a></li>`
for the second value (if there is a 2nd) I would like the do the following
`<li><a href="the taxonomies link">How Taxonomy Name can benefit you</a></li>`
Basically how ever many taxonomies there I only want to show 2 and I want to be able to use them as above? Is this even possible? | I would use `wp_get_object_terms` which will return an array of object terms that you can manipulate. You also have a little more control with sorting the terms.
<?php
$terms = wp_get_object_terms($post->ID, 'work', array('orderby' => 'name', 'order' => 'ASC'));
if(is_array($terms)) : ?>
<ul>
<?php if(isset($terms[0])) : ?><li><a href="<?php echo get_term_link($terms[0]); ?>">Find out more about <?php echo $terms[0]->name; ?></a></li><?php endif; ?>
<?php if(isset($terms[1])) : ?><li><a href="<?php echo get_term_link($terms[1]); ?>">How <?php echo $terms[1]->name; ?> can benefit you</a></li><?php endif; ?>
</ul>
<?php endif; ?>
Obviously, this is not a very dynamic solution and will only work for your first two terms, but these functions should help you sort out the correct solution for you. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "custom post types, custom taxonomy, taxonomy, terms"
} |
how do I get_sidebar into a varaible?
I want to get a sidebar and save it in a Variable,
This is impossible with the get_sidebar function since it simply prints out
the sidebar, is there another function that I can use? | You probably need to use output buffering, if I understand your question correctly.
Try something like this:
ob_start();
dynamic_sidebar('sidebar-id');
$sidebar = ob_get_contents();
ob_end_clean();
That will put the output of the sidebar into the variable $sidebar, which you can then process and return from your filter on the page content. | stackexchange-wordpress | {
"answer_score": 17,
"question_score": 6,
"tags": "sidebar"
} |
How to enqueue scripts on custom post add/edit pages?
I'm trying to enqueue a JS script only when someone is adding or editing a custom post type I created called "recipes". Currently the script works ok when I do this:
if (is_admin()){
wp_enqueue_script( 'my-script' );
}
But this loads it in every admin page, I'm assuming I need to hook it to a function but I hvae no idea what it'd be.
Thanks in advance! | You can do it like this (put in your `functions.php`) :
function add_admin_scripts( $hook ) {
global $post;
if ( $hook == 'post-new.php' || $hook == 'post.php' ) {
if ( 'recipes' === $post->post_type ) {
wp_enqueue_script( 'myscript', get_stylesheet_directory_uri().'/js/myscript.js' );
}
}
}
add_action( 'admin_enqueue_scripts', 'add_admin_scripts', 10, 1 ); | stackexchange-wordpress | {
"answer_score": 56,
"question_score": 27,
"tags": "custom post types, javascript, hooks, wp enqueue script, actions"
} |
Hide links to pages that dont have any content
Its that possible?Than when something is added to page in admin panel, page link to that page appears. | I think you would need to implode(',',$excluded_pages) for things to work,
$excluded_pages = array();
$all_pages = get_pages();
foreach ( $all_pages as $the_page ) {
if ( '' == $the_page->post_content ) {
$excluded_pages[] = $the_page->ID;
}
}
wp_list_pages( array(
'exclude' => implode(',',$excluded_pages)
) );
**EDIT** | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "pages, links"
} |
Allowing WordPress.org/com accounts on a self-hosted install
Hopefully a basic question, but one that plagues me nonetheless.
I have a couple of self-hosted WordPress installs on my website. An issue that I have is that I have common users registered for each site....however some of them feel its a pain to have to go through the signup process each time, and have to juggle multiple accounts in order to comment.
Is it possible to commonize accounts, for instance simply using a WP.com/org account and accessing my blogs in that manner? | I _think_ WordPress. **com** is an **OpenID Provider**, meaning that you can use the OpenID Plugin, and allow users to use their WPCOM account to register/login to your site.
As far as I know, WordPress. **org** is **not** an OpenID Provider (though that would be a neat idea!). | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "comments, user access"
} |
How to get Images included in Post
is possible to get images added to a post programmatically? I am working on custom template (my first) and I need to display Images added to a post in specific way.(first image as title image and the rest of imgs only render into hidden img tags (will be visible through lightbox slideshow).
So is there any function like `get_post_attachments('type'=>'image')` whose output I would be able to iterate over a loop?
Thanks for your help | You can use `get_posts()` (Codex ref for getting Post attachments).
<?php
$args = array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID
);
$attached_images = get_posts( $args );
?> | stackexchange-wordpress | {
"answer_score": 5,
"question_score": 5,
"tags": "posts, theme development, images, templates"
} |
Get the Page Content,without generating HTML
I want to get the page content (so i can parse the tags/short-codes in it), but i don't want to output the result itself to the browser (i.e. echo=0).
I tried get_the_content(); but its the same deal. | Where are you doing your code parsing? If you're doing it directly in the template file, inside the Loop, then you should be using `get_the_content()`.
However, it might be more efficient to filter `the_content()`, via the `the_content` filter. e.g. in `functions.php`:
function mytheme_filter_the_content( $content ) {
// add code here to filter the_content
// which is contained in the $content variable,
// then return $content
return $content;
}
add_filter( 'the_content', 'mytheme_filter_the_content' );
**EDIT**
If, for whatever reason, you just want to parse `the_content()`, pull out the shorcodes, and _execute_ them, use `do_shortcode()` (Codex ref). e.g.:
<?php
$page_content = get_the_content();
$page_shortcodes = array() // ...some array that includes whatever shortcodes you found
foreach ( $page_shortcodes as $page_shortcode ) {
do_shortcode( $page_shortcode );
}
?> | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "pages, content, the content"
} |
have_comments not true for logged out visitors?
For some strange reason, comments aren't being displayed when a user is _not_ logged in. I've done some extensive experimenting with comments.php without any success. Here's a reference to the example page:
<
If you are logged in, you would see 3 comments. If you are not logged in, nothing but the form. Also, to add to the mystery, when "editing" the post from within the admin and clicking "show comments", it tries and is not able to load the comments.
It appears that the "have_comments" conditional is failing for logged out users. I've also tried getting wp_list_comments to return the list with no success.
I've checked for plugin conflicts and nothing obvious yet. Have any of you run into this? Any obvious answers? | Toscho was right. I wound up having a query that was getting in the way. It took a bit of troubleshooting to figure out, but I nailed it.
If you run into similar issues, look carefully for any custom queries you may have on the template and make sure that you've wrapped them up properly. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "comments"
} |
Create a shortcode in Wordpress, again
There're lots of examples both here and on the internet, I've tried but don't seem to be able to achieve what I need although it does feel like it should be simple enough.
Basically, I want to be able to use a shortcode like this:
[download]
and I need Wordpress to output this:
<a class="download" href=" file</a>
<a class="download" href=" file</a>
Your help would be greatly appreciated. Thanks so much! | // Declare your shortcode
add_shortcode("download", "downloadFunction");
// Second Declare your shortcode function
function downloadFunction($att, $content, $code){
// your function is passed 3 Arguments
// $atts : this is an array of the shortcode's attributes
// $content : this is the content between the code. in your case the file url.
// $code : this is the code used. in this case it will be download.
// here we only need the $content of the shortcode which we place for the file
$return = '<a class="download" href="'.$content.'">download file</a>';
$return .= '<a class="download" href=" file</a>';
// we then return the result.
return $return;
} | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 2,
"tags": "shortcode"
} |
How can I have network sites not use year/month folders by default?
When creating a new network site, by default the site option `Uploads Use Yearmonth Folders` is on (set to `1`). I have to set it to `0` each time I create a new site. This isn't horrid, but is it possible to make this the default for newly created sites? Perhaps a hook or something I am overlooking? | You could just change the option after the blog is created:
add_action('wpmu_new_blog', function($blog_id){
switch_to_blog($blog_id);
update_option('uploads_use_yearmonth_folders', false);
restore_current_blog();
});
Drop this code into a .php file inside wp-content/mu-plugins | stackexchange-wordpress | {
"answer_score": 5,
"question_score": 4,
"tags": "multisite, uploads"
} |
After finishing building a site on localhost, how do I transfer everything to a client's server?
I have installed XAMPP to build a site on localhost. After I finish, how do I transfer everything efficiently to, say, a client's server? | See Moving WordPress « WordPress Codex and Backing Up Your Database « WordPress Codex and How to Move WordPress Blog to New Domain or Location » My Digital Life and possibly Giving WordPress Its Own Directory « WordPress Codex
Deleted this added link as it advocates using a texteditor to change URLs in the dump; that will break serialized data. Use the SQL statements in How to Move WordPress Blog to New Domain or Location above. See Why is my database import losing text widget data? | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "migration, localhost, xampp"
} |
Function to list all post slugs for every post in my WP database?
Function to list all post slugs for every post in wp_posts table?
I assume there's an official function to generate a post slug, but maybe someone here already has the answer. | example - unordered list with post slugs:
<ul>
<?php foreach( get_posts('numberposts=-1') as $post ) {
echo '<li>' . $post->post_name . '</li>';
} ?>
</ul>
< | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 2,
"tags": "slug"
} |
How do I remove dashboard access from specific user roles?
I'd like to prevent certain user roles from accessing the dashboard < at all. I've moved and restyled user profiles to a new page that's viewable on the site. How would I go about doing this? | To lock subscribers and contributors out of the admin:
function wpse23007_redirect(){
if( is_admin() && !defined('DOING_AJAX') && ( current_user_can('subscriber') || current_user_can('contributor') ) ){
wp_redirect(home_url());
exit;
}
}
add_action('init','wpse23007_redirect');
Hope that helps. All roles give the user a capability that is the name of that role, so you can use any role name as a capability. | stackexchange-wordpress | {
"answer_score": 26,
"question_score": 13,
"tags": "admin, user roles, dashboard"
} |
Control attachments menu order with jQuery Sortable
I've managed create a metabox that lets me upload and then fetch the images and then also been able to add jquery ui sortable to be able to sort the images, however I've no idea how to add actual functionality so that the sort order get saved.
If someone has an idea how to achieve this or some tutorial that would be helpful, please share, I'm helplessly stuck here.
Thanks.
Edit: Basically, what I need to know is how to tie jQuery sortable together with the functionality that handles the different attachments menu_order. | To save the menu order use `wp_update_post()` with each attachment ID and its new menu position:
$thisattachment = array();
$thisattachment['ID'] = $thisid;
$thisattachment['menu_order'] = $new_menu_position;
wp_update_post($thisattachment);
EDIT - assuming these are already attachments and you're updating them? Otherwise you have to insert the attachments first with wp_insert_attachment | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "attachments, ajax, media library, sort, jquery ui"
} |
WordPress twenty eleven sidebar on Pages
I am using 2011 theme, any how I managed to get sidebar on single.php pages by installing child theme,
But now I want sidebar on pages,
How do I get it? | Funny you should ask, I've just posted an How to tutorial on how to add a sidebar on posts and pages in Twenty Eleven | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 1,
"tags": "pages, sidebar, theme twenty eleven"
} |
Is there way to rename user role name without plugin?
Is there anyway to rename a user role name via hook, instead of using plugin?
### Edit
For example, `administrator` » `owner` | function change_role_name() {
global $wp_roles;
if ( ! isset( $wp_roles ) )
$wp_roles = new WP_Roles();
//You can list all currently available roles like this...
//$roles = $wp_roles->get_names();
//print_r($roles);
//You can replace "administrator" with any other role "editor", "author", "contributor" or "subscriber"...
$wp_roles->roles['administrator']['name'] = 'Owner';
$wp_roles->role_names['administrator'] = 'Owner';
}
add_action('init', 'change_role_name');
< | stackexchange-wordpress | {
"answer_score": 47,
"question_score": 29,
"tags": "user roles, capabilities"
} |
Post & edit a post from front end along with upload, dropdown, and other inputs
I am following this tutorial to post from front end. I am able to post the title, content, category, tags, I would like to know is it possible to add more fields like in the image below. How to increment field-set? and how to add edit the post from the front end itself?
basically this what I want to do. !front end post with advanced fields | I believe it is better if you use the ajax method instead of sending the POST to the same page.
You can use javascript to increment the form / fieldset. Use an array for the name e.g
<input type="text" name="ingredient[]"/>
If you want to edit the post, just you us the saved data on the value attribute, e.g
<input type="text" name="ingredient[]" value="<?php echo get_post_meta($post->ID, 'ingredient[0]', true) ?>"/>
If the post meta using a same meta_key, just put it in the for each loop.
Hope this help | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "posts, theme development, front end"
} |
remove "edit your profile" from admin menu bar
How can I remove "edit your profile" submenu under "my-account-with-avatar" admin menu bar, while still keeping the avatar and logout? | There is a `remove_menu` hook for the admin menu bar.
The class you want to hook into `$wp_admin_bar` , you can see the remove function here and test it out since there is no documentation on it ( line 86), it should work with the submenu ID.
<
**Since you did not seem to believe me here is the code.........**
function ya_do_it_admin_bar_remove() {
global $wp_admin_bar;
/* **edit-profile is the ID** */
$wp_admin_bar->remove_menu('edit-profile');
}
add_action('wp_before_admin_bar_render', 'ya_do_it_admin_bar_remove', 0); | stackexchange-wordpress | {
"answer_score": 12,
"question_score": 8,
"tags": "menus, admin bar"
} |
Disable the link on certain pages
I currently have a site with two levels of navigation. I am styling the wp_list_pages() list to act as my navigation.
I would like to disable the link on some pages which have children (not exclude) so that I can hover over them to display the drop down navigation but I can't click on them.
Does anyone know of such a method or parameter I could add? | You could go to the wordpress menu and make the target of the link a #. If the user clicks on it, they are taken to the top of the page where they probably are anyway since they're using the navigation. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "exclude, wp list pages"
} |
Wordpress Enqueue for homepage only, functions.php, wp-framework
I'd like to replace my:
if(is_home())
{
wp_enqueue_script( 'homestuff', get_theme_part( THEME_JS . '/home.js' ), array( 'jquery' ), null, true );
wp_enqueue_script( 'jquerycolor', get_theme_part( THEME_JS . '/jquery.color.js' ), array( 'jquery' ), null, true );
};
Which is currently in header.php, by putting it in a functions.php file instead. Trying to tidy everything up on a sprawling client's site. I'm using wp-framework and ideally would stick this inside the enqueue_assets function in the main parent_theme class. Although this isn't really a wp-framework issue, I'd just like to know:
How can I get is_home() to work from a functions file? Is there an alternative, using globals, I need to know about? | First, if you want to target the _site Front Page_ , you need to use `is_front_page()`. The `is_home()` conditional returns true when the _blog posts index_ is displayed, which may or may not be on the _site Front Page_.
Second, you need to hook your function into an appropriate hook, which it appears in this case is `wp_enqueue_scripts`.
(Also: what is `get_theme_part()`? Is it a custom function in WP Framework?)
For example, you can do this in `functions.php`:
function mytheme_enqueue_front_page_scripts() {
if( is_front_page() )
{
wp_enqueue_script( 'homestuff', get_theme_part( THEME_JS . '/home.js' ), array( 'jquery' ), null, true );
wp_enqueue_script( 'jquerycolor', get_theme_part( THEME_JS . '/jquery.color.js' ), array( 'jquery' ), null, true );
}
}
add_action( 'wp_enqueue_scripts', 'mytheme_enqueue_front_page_scripts' ); | stackexchange-wordpress | {
"answer_score": 25,
"question_score": 10,
"tags": "functions, wp enqueue script, homepage"
} |
Extending post by email
Just putting my feelers out on this one, I need to be able to accept incoming emails and add them as posts, however I want to be able to do a bit of processing first, for example I want to change the slug, prepend a string to the title etc.
Is there a way I can hook into the email function, change some data and then let it continue. I also might want to reject the email if it isn't sent from an approved domain (this will be a field in a custom post type).
Are my requirements achievable or am I barking up the wrong tree?
**Edit**
I have discovered the `save_post` hook, although it fires after the post has saved... not really what I'm looking for. Is there a hook that gets fired before a post is saved, giving me all the info about the post, especially where it's been created from.
**Edit 2**
Alternatively is there a way to add a post manually... so I handle the receiving of the email with my own code + cron, then have an API to create a new post with? | If you dig into the code of postie _(plugin)_, you'll probably find your answer. In particular, see the filter sample files, and then trace backwards from there. From the FAQ:
> **Can I add special text to the body of the post when using postie?** ,
>
> Yes. You can create your own function, and use the postie_post filter. Two short examples are included in the filterPostie.php.sample file
Of note - per this ticket: post by email is slated to be dropped from WP core and switched over to a plugin, so you might be better-off switching to a plugin-based solution now, rather than building your functionality around the current core post by email functionality. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "custom post types, posts, email"
} |
How to regenerate image thumb with size that is specified in media section
I have 500x300 sized images in my all post and want 280x177 sized images to display in index page for all the post. I used regenerate thumbnails and AJAX thumbnail rebuild plugin which builds images using setting in media section but problem is that after building some of the images it stops reacting and just hangs. Why this is happening? Is these plugins not work with more images. I have approximately 2000 images. Please help me. How to rebuild this images. Thanks in advance.... | Very likely, your issue is the large number of images, causing the processing to time out.
Try increasing your PHP script execution time, and see if either Plugin can complete.
Alternatively, I believe that one or both of those Plugins allows for manual thumbnail regeneration, via `Dashboard -> Media`. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "post thumbnails"
} |
Updating a Wordpress plugins breaks SVN
I have a blog with all the plugins I need committed to an internal svn repository. Wordpress is showing that some plugins need to be updated but when I do, Wordpress will delete the folder for that plugin so the .svn files are deleted as well. This will break the repository for that plugin. Any way around this? | a simple way around this is to update the plugins by SVN from the plugin repository. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 3,
"tags": "plugins, svn"
} |
Help!! I Screwed up my WP
I was trying to clear up some empty tables left behind by other previously used plugins. As such i was trying to delete the GD Star rating plugin and now I cannot access my WP admin. i get the `'You do not have sufficient permissions to access this page'`
I turned on the debug to true and saw the errors caused by lots of plugins. So I disabled all of them, but nothing helps:
This was the query I had run (and then just checked the output and clicked 'Drop' which messed it up.
SELECT *
FROM `mydomain_main`.`wp_options`
WHERE (
`option_id` LIKE '%ratings_%'
OR `blog_id` LIKE '%ratings_%'
OR `option_name` LIKE '%ratings_%'
OR `option_value` LIKE '%ratings_%'
OR `autoload` LIKE '%ratings_%'
)
Can someone please please advise | since i posted as a comment and most people miss the good tips that are in the comments, I'm posting again as an answer
The reason is because `GD Star rating` plugin creates custom capabilities and your query deleted all references of `%rating%` it deleted the `wp_user_roles` option which holds all capabilities roles.
the solution would be to re create that option in options table (usually wp_options) with the default value just like I answered **here** . | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 0,
"tags": "plugins, mysql"
} |
how do I exclude child categories from a wp_query?
I'm doing a category-based search that looks like this:
$feed = WP_Query("category_name=noticias&showposts=3&order=DESC");
The problem is this also brings me posts from the child categories, which I would like to avoid... how do I do this?
If I do something like
$feed = query_posts(array('category__in' => array(102)));
Then I am told that $feed is not an object next time I try to do something with it... that's why WP_Query was good for me in the first place. | you can use the `'category__in'` in WP_Query; example:
$feed = WP_Query(array('category__in' => array(102), 'posts_per_page' => 3, 'order' => 'DESC')); | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "wp query"
} |
Change maxlength of link_description in dashbord link section?
Im using wordpress together with qtranslate and it works on pages and post but not in menus, widgets etc. So i created jquery scripts to solve those issues. The problem is that the field "link_description" in wordpress link section is limited to 30. Using two languages or more, 30 characters is not enough. Is it possible to change or even remove this property without modifying any core files? | First of all, "link description" is defined in the database structure as VARCHAR(255), and I don't think there's anything in core limiting the size of the field farther. Are you sure that you can't fit more than 30 characters in your bookmark descriptions?
That said, 255 characters can still be small if you are trying to fit several different language translations into the field. However, there's nothing stopping from you from simply redefining the column type in MySQL so that it can hold more data. Defining that field as "TEXT" would let you store up to 64K in it, and you wouldn't have to modify any core files to take advantage of that change. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "wp admin, links, dashboard"
} |
How to list "invisible" Auto Drafts?
I noticed that when starting to create a new post, and only attach images and then when leavning the post for some reason, it won't show up in the list post view. However when you look in the Media Library you'll see that the image is attached to "Auto Draft" and that the post really exists.
Now, I find this useful, and would like to be able to list these Auto Drafts in the post view, but I don't really know what I need to do to list them.. Ideas? | try pasting this in your theme's functions.php file
add_filter( 'parse_query', 'display_autosave_and_revisions' );
function display_autosave_and_revisions( $query )
{
global $pagenow,$typenow;
if ( is_admin() && $pagenow == 'edit.php' && $typenow == "post") {
$query->query_vars['post_type'] = array('revision','post');
$query->query_vars['post_status'] = 'any';
}
} | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "attachments, editor, draft, listing"
} |
Custom CSS for plugin form
I have a short code that is adding a form to a page. How do I ensure that the CSS for the form is loaded in time with the shortcode? | you can check with `the_posts` hook if your shortcode exists and only enqueue the style if so :
function check_for_shortcode($posts) {
if ( empty($posts) )
return $posts;
$found = false;
foreach ($posts as $post) {
if ( stripos($post->post_content, '[CHANGE_TO_YOUR_SHORT_CODE') )
$found = true;
break;
}
if ($found){
$url = get_bloginfo( 'template_directory' );
wp_enqueue_style( 'my_login_Stylesheet',$url.'/my_login_Stylesheet.css' );
}
return $posts;
}
add_action('the_posts', 'check_for_shortcode'); | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "plugins, css, shortcode, forms"
} |
How to disable pagination (next/previous links) on post type archive?
How can I remove the next and previous links in a custom post type archive page, but only for that post type?
I know I could wrap any function in `if ( get_post_type($post) == 'myposttype' ) {}` but I can't find a solid snippet to remove the pagination.
I have tried a few solutions, this being one of them, but nothing is working. And yes, I did try removing them from my template. :)
!next page link | Got it figured out...
While I did manually remove the next page links, CloudFlare's cache was not playing nice. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "pagination, archives, custom post type archives"
} |
How to change a custom query into a standard loop?
I'm trying to modify how results are displayed in a post list that's currently controlled by the code below. However, it's not built in the WP_Query `while ( $the_query->have_posts() ) : $the_query->the_post();` style I'm accustomed to and have built a lot of shortcodes and loop styles around.
How can I change the code below into a "regular" Wordpress loop that will allow me to use template tags like the_title()?
$totalposts = $wpdb->get_results($querystr, OBJECT);
$wp_query->request = $querystr . " LIMIT " . $ppp . " OFFSET " .$offset;
$results = $wpdb->get_results($wp_query->request, OBJECT);
foreach ($results as $result) {
$offset++;
$output .= '<a href="'.get_post_permalink($result->ID).'">' . $result->post_title . ' (' . $result->post_date . ')</a><br>';
} | In order to be able to use template tags, you have to do two things after getting your custom select query:
1. You have to declare the `global $post` variable.
2. You have to call the setup_postdata($post) function to populate the variables.
So, my code had to be changed like so:
$results = $wpdb->get_results($wp_query->request, OBJECT);
global $post;
foreach ($results as $post) {
setup_postdata($post);
?>
<h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
etc.
The key to this is on this codex page:
Displaying posts using a custom select query | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "wp query, loop, wpdb, template tags"
} |
How can I make my website with wordpress having on-spot editing feature as compared to concrete5 CMS?
I hope you were easily able to understand my situation through the question.
1.Do we have any theme or plugin for on-spot editing the post by people or by me after the blog post is posted?
2.If there isn't any theme or pluggin for such feature should I make plugin or theme independently for my website.
3.If both of the above fails,please give me a better option for some other kind of CMS as there are no many cms and I want to make my website with dynamic features. Please follow the link below and kindly suggest me one.
< | This is typically called _edit in place_. Try the Front End Editor plugin. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": -1,
"tags": "plugin development, theme development, cms"
} |
problem redirecting users to page on login
I'm trying to redirect certain users to a part of my site but I cannot seem to make it work... can you take a look at this and tell me what I'm doing wrong?
if ( ! function_exists( 'redirect_after_login' ) ) :
function redirect_after_login() {
global $user_ID;
if ( $user_ID === 4 ) {
global $redirect_to;
if (!isset($_GET['redirect_to'])) {
$redirect_to = get_option('siteurl') . '/stock-de-sexitive/';
}
}
}
endif;
add_action('auth_redirect', 'redirect_after_login');
Also, I know globals are dangerous, so if you know of a canonical approach that would be great too | Try `wp_redirect()`. And don't forget to exit. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": -1,
"tags": "redirect, wp redirect"
} |
What are the correct permissions so WP doesn't ask for FTP credentials if installing plugin?
My nginx user is www-data. If I do `su www-data` I can create both file and directory.
But when installing plugin I am asked for FTP credentials.
I tried to give the public_html directory 777 permissions for a while to test if I can install plugin without providing FTP credentials but it didn't help either.
* WP 3.2.1
* nginx
* ubuntu
How can I install plugins without providing FTP credentials. | You can set this in the wp-config.php, check the Editing wp-config.php page in the docs. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 0,
"tags": "plugins, installation, permissions"
} |
How can I query posts from multiple roles?
I'm using the code below from another answer to query posts from 1 custom role, eg "friends". I thought I could just comma separate the roles to list posts from more than one role, but this didn't work. Is there another way I can write it? I've tried `'role' => 'friends', 'enemies'` and `'role' => 'friends, enemies'` but I guess `get_users` only supports one role.
<?php
$friends = get_users( array( 'role' => 'friends' ) );
$friend_ids = array();
foreach( $friends as $friend )
$friend_ids[] = $friend->ID;
$news = new WP_Query( array( 'author' => implode( ',', $friend_ids ), 'post_type' => 'news', 'paged' => get_query_var('paged') ) ); ?> | Just do the get_users() twice and merge the results:
<?php
$friends = get_users( array( 'role' => 'friends' ) );
$enemies = get_users( array( 'role' => 'enemies' ) );
$friends_n_foe = array_merge($friends, $enemies);
$IDs = array();
foreach( $friends_n_foe as $person ) {
$IDs[] = $person->ID;
}
$news = new WP_Query( array( 'author' => implode( ',', $IDs ), 'post_type' => 'news', 'paged' => get_query_var('paged') ) );
?> | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 2,
"tags": "wp query"
} |
Rename Smart YouTube's httpv back to http for all posts
I've used the Smart YouTube plugin to embed YouTube videos into my blogs. The way I did it is to replace the ` of the YouTube url with `httpv://` as the plugin describes.
But now I noticed that it's much easier to just auto-embed the YouTube videos by posting the normal ` url. I would like to disable the Smart YouTube plugin and convert all those `httpv://` back to ` Is there a good automated way to do that?
Here's an example blog post of mine that now has Smart YouTube disabled so there's just a `httpv://` url lingering there. | I like to use the Search Regex plugin for mass post editing.
< | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "plugins, shortcode, embed, youtube, customization"
} |
Please suggest me some plugins in WordPress networking
Hey guys i'm creating a site network using WordPress. Lets say my site name is blahblah.com and lets say i have 10 subdomains like site1.blahblah.com,site2.blahblah.com
Now i want something like this. There will be no articles in my main domain. But i want list all subdomain's articles in my main domain. When they click read more button users have to redirected to original article.
I also want multisite access facility with single registration. That is if a user signed up in my main domain, then he should able to access all my sub domain using the same login credentials. Some says use the same database for all domains. But i dont think thats a good idea. Is there any premium or free plugin available for this feature?.
Thanks. | There are two plugins that do exactly what you want, and I have used them both extensively.
First, ThreeWP-Broadcast. This plugin lets you "broadcast" posts from your sub blogs to your main blog (or the other way around). It also allows you to link to broadcasted post to the original, as well as auto create tags, categories, custom fields, and featured images.
Second, is Multi-Site User Management. This is a little plugin that you drop in your mu-plugins folder and it will keep your users synchronized across all sites, allowing them to login into all the sites with the same name. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "user registration, multisite, network admin"
} |
Splitting an eCommerce store from the WordPress Theme
Company I work for has purchased an eCommerce solution for WordPress. The solution works as a complete WordPress Theme. My assignment is to split the store view from the original website design.
To be more precise, website we are working on has a unique design, but when we install the store theme, the whole website theme changes to that of a store.
Are there ways I can complete this assignment? I thought about it for a while but the solution I found is terrible. I wanted to allow access to a store only on one particular page, by checking
<?php if is_page('shop') {
include TEMPLATEPATH.'storeurl/header.php';
} else {
get_header();
} ?>
and so on, but it gets me nowhere because I need to have certain fields in admin panel for adding products.
Any other ideas, please? | Core site functionality really shouldn't be so tightly coupled to the theme. This is why the plugin system exists. If it's not too late I would recommend exploring alternatives.
That said, anything happening on the admin side is in the theme's `functions.php` file, or is included via that file. As long as that file and anything it loads is in the proper place it's likely the admin side will work. Then it's a matter of merging or including the other templates into your own theme to get the presentation you want on the front end. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "theme options"
} |
Comma seperated list of ID's as an array?
I have the following code that prints a comma separated list which I need in the form of an array, how do I get the list of id's into an array called $excluded_categories with contents as per below?
$categories = get_categories(array('taxonomy'=>'projects_category', 'exclude'=>7, 'orderby'=>'id'));
if ( !empty( $categories ) ) :
foreach($categories as $term){
echo $term->term_id.', '; // prints: 1,2,3,4,5,6,8,9,
}
endif;
$excluded_categories would be an array containing: 1,2,3,4,5,6,8,9 | WP has a lot of nifty functions in the corners for such stuff. Try this:
if ( !empty( $categories ) ) {
$excluded_categories = wp_list_pluck( $categories, 'term_id');
$excluded_categories = implode(',', $excluded_categories);
} | stackexchange-wordpress | {
"answer_score": 8,
"question_score": 0,
"tags": "array"
} |
What is 'term_group' for 'order_by' in get_terms()?
I was just reading the Codex regarding `get_terms();`. What exactly is the parameter `'term_group'`?
You can use it in ( _example_ ): `'order_by'` for `get_terms();`.
_Hint: I could be all terms that share the same names, but have different slugs._ | The idea of term groups was to have a term with multiple aliases.
This feature doesn't seem to be fully backed and is therefore practically never used. | stackexchange-wordpress | {
"answer_score": 14,
"question_score": 20,
"tags": "terms"
} |
[Plugin: Posts 2 Posts] Controling the display order of connections
My question resembles one I asked before:
[[Plugin: Posts 2 Posts] Changing display order of connections](
But now I want to display the connection in the SAME order I created them ! That is, if I attache quote#1 THEN quote#2 to an article, I want quote#1 to appear before quote#2 regardless of the creation date of these quotes, their alphabetical order or whatever. Don't know if I make myself clear o_O | With the development version of the plugin (0.8-alpha), you have a 'p2p_orderby' query var, which you can use with WP_Query, like so:
$my_query = new WP_Query( array(
'connected_to' => get_queried_object_id(),
'p2p_orderby' => 'my_connection_field'
) );
More info on connection fields:
<
Note that this is alpha software and you still have some work to do on your own. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "plugin posts to posts"
} |
Large size image breaks template layout
If I upload a large size image inn my wordpress, the image breaks my template width. I have seen some templates which scale the large image's width to the maximum width of the post div. What CSS or code I need to change for that purpose? Thanks. | In your `functions.php` file, you need to define `$content_width`, which will cause WordPress to scale **large** -size images, and also embedded videos, accordingly.
e.g. if the width of your content area is 600px:
if ( ! isset( $content_width ) ) {
$content_width = 600;
}
You will probably also want to add accompanying CSS, e.g.:
#content img {
width: auto;
max-width: 600px;
height: auto;
}
That way, when the image is scaled, it will maintain its proportion; rather than merely having its width reduced, the height will also be scaled proportionately. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "images"
} |
Editing Footer Information
I just built a theme for a client. I am wondering what is the best way to make footer content editable through Wordpress. The footer info looks like this:
* Company Name
* Address Line 1
* Address Line 2
* Phone and Fax
* Email (linked with mailto)
I have some ideas on how to do this:
1. Make a page called footer and grab the content from there.
2. Widgetize the footer and make it a text widget
3. Make a themes option panel with the option to customize this text
I would love to know what you guys think is your best solution to this.
Thank you in advance! | I would go with a Widgetized footer.
If you want to go the extra mile, rather than create Theme Options, simply create a custom Widget, e.g. Footer Contact Details, that has editable text inputs for Company Name, Address Lines 1 and 2, Phone/Fax, and Email. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "theme development"
} |
Excerpts automatically remove paragraph space
I use excerpts of posts in my front page. In my excerpt, the summary of the post seems to be clumped together with no spaces that are indicated in the post (e.g., paragraph spaces are automatically removed). I understand this is the default behavior.
Question: Is there a way to retain the paragraph in excerpts?
To show excerpt on the fron page in my Twenty Ten theme's loop.php I changed this (around line #137:
<?php if ( is_archive() || is_search() ) : // Only display excerpts for archives and search. ?>
with this:
<?php if ( is_home() || is_front_page() || is_archive() || is_search() ) : // Only display excerpts for archives and search. ?>
thanks. | Looks like my other answer wasn't working, so I looked into it and found this:
<
That article should give you all you need to keep the `<p>` tags in there. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "excerpt"
} |
List of Body Classes Generated by body_class()
Does anyone know where I can get a _list of all the **body classes_** generated by `body_class()` for **every sections** and **every conditions** , including _custom post-types_ , etc.?
For example, for a _search result_ page with certain conditions (eg. _logged-in_ ), the function produces this:
<body class="search search-results logged-in admin-bar single-author two-column right-sidebar">
I need the full list for **reference** in creating a theme.
Cheers! | Several classes have been added since WordPress 2.8 (when the WPEngineer post was written). I would refer directly to the `body_class()` Codex entry, which currently lists the following:
* rtl
* home
* blog
* archive
* date
* search
* paged
* attachment
* error404
* single postid-(id)
* page-id-(page_id)
* attachmentid-(id)
* attachment-(mime-type)
* author
* author-(user_nicename)
* category
* category-(slug)
* tag
* tag-(slug)
* page-parent
* page-child parent-pageid-(id)
* page-template page-template-(template file name)
* search-results
* search-no-results
* logged-in
* paged-(page number)
* single-paged-(page number)
* page-paged-(page number)
* category-paged-(page number)
* tag-paged-(page number)
* date-paged-(page number)
* author-paged-(page number)
* search-paged-(page number)
* tax-(taxonomy name) (since 3.1)
* term-(term name) (since 3.1)
* admin-bar (since 3.1) | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "functions, post class, references"
} |
"Print to printer" functionality in a plugin
I want to add "print" button to print simple reports in a plugin. The basic idea I have is to generate a printer friendly html page and redirect user to that page where he/she can use browser's print functionality.
How good is that solution? Is there any other alternative? | check out **WP Print Friendly** plugin which extends WordPress template system to support printer-friendly templates. Works with permalink structures to support nice URLs. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "plugin development"
} |
Hosting multiple Wordpress sites on single server - best practices?
I rent some webserver space (Linux, MySql, PHP, Apache) and host several Wordpress websites (for different clients, with different needs) What would be the best way to Host multiple wordpress sites on a single machine, what I'm looking for here, is saving on diskspace and number of databases needed as well as simplifying maintenance.
* Yes this should be for a single wordpress version.
* Each site should be able to have different plugins included and activated
* Each site should be able to have it's own themes (some shared some not)
* No crossing between sites - users and content not shared in any way.
* Easily Upgradable
* Single Super Admin is a plus but not essential (I know how to install and manage wordpress, I can't figure out if Wordpress MU is what I need, if so how to set it up so that my requirements are met, can I enable/disable features per user/blog created with MU).
Thank you! | Based on your needs, yes: you should probably be using a Network (WordPress with MultiSite enabled).
* All network sites run the same version of WordPress
* Each network site can activate its own Plugins. You can explicitly allow each site to manage its own Plugins.
* Each network site can have access to different Themes (though you will have to manage access to each Theme via the Network Admin.
* Users can be managed such that each sites users are mutually exclusive
* Upgrades of WordPress core, Themes, Plugins, and network sites is all managed from a single location in the Network Admin
* Super Admin is part of a Network install, and allows granular control over each network site, Plugins, Themes, and users.
As for how to set up a Network, everything is incredibly well-documented in the Codex. | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 5,
"tags": "linux, hosting, configuration"
} |
How do I add a widget from an Android phone?
Currently my only internet access is via my phone, and I need to add a widget to a Wordpress site. This requires dragging and dropping the widget to the sidebar, which I cannot do via the web browser on the device. Is there some way to get around this? | Yes at the top of the page click on "Screen Options" then click **"Enable accessibility mode"** , | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "widgets, mobile"
} |
preselected custom fields in custom post type
I have a custom post type called "stock" and each post is going to have a stock_id, stock_name, stock_description and stock_available fields,...I would like to have defaults for these fields so the user doesn't have to load them on each new item. Is there a way? | A simple way to do that would be to use **Verve Meta Boxes** plugin which lets you define a metabox with a simple UI ( **no code is needed** ) and you have an options to set the default value for each field. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "custom post types, custom field"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.