INSTRUCTION
stringlengths 11
999
| RESPONSE
stringlengths 0
999
| SOURCE
stringlengths 16
38
| METADATA
dict |
---|---|---|---|
How to get the path to the current theme?
This code is used to get the directory of the current plugin: `plugin_dir_url( __FILE__ )`.
What should I use to get the directory of the current theme? | I think you have to be a little careful because it depends on what you are trying to do.
If you are using a child theme `get_template_directory();` will still go to the parent theme. However `get_stylesheet_directory();` will go to the current theme, child or parent. Also, both these functions return absolute server paths.
If you wanted a fully formed URI, for links or images, you should use `get_template_directory_uri();` or `get_stylesheet_directory_uri();` using the correct one for the reasons stated.
### Summary
* `get_stylesheet_directory()`: file path to current Theme directory
* `get_stylesheet_directory_uri()`: url path to current Theme directory
* `get_template_directory()`: file path to parent Theme directory
* `get_template_directory_uri()`: url path to parent Theme directory | stackexchange-wordpress | {
"answer_score": 79,
"question_score": 41,
"tags": "plugin development, theme development, directory, paths"
} |
Unable to upload data to Media Libary
I uploaded wordpress to my server. Everything works fine so far. But when I try to upload data to my media libary nothing happens. Doesn't matter if I click the "Select Files" or "browser uploader" just nothing happens. I never had those kind of problems before. The permission for the wp-content/uploads/ folder is on 777. I have absolutely no conclusion what could be the problem here? Any suggestions?
Regards, Nils | function load_scripts() {
wp_deregister_script('jquery');
wp_register_script('jquery', ("
wp_enqueue_script('jquery');
}
add_action('init', 'load_scripts');
I have found the problem now (for all the following readers). In my template functions.php I've included the latest version of jQuery. So jQuery has been included in the admin panel too. The fact that Wordpress loads jQuery in the admin panel twice must have caused the issue. I solved this by adding the conditional tag is_admin to the function add_action
if(!is_admin()) {
add_action('init', 'load_scripts');
} | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "forms, uploads"
} |
Make view count for pop up post
I'm using SimpleModal to allow users to click on a post excerpt on my homepage and popup a box showing the full post. However it doesn't count for an actual view of the post when this happens. Is there a way to make wordpress recognize it as a view? I'm using wp-postviews to track view counts. | Apparently the plugin does the logging inside the `wp_head` hook:
add_action('wp_head', 'process_postviews');
so make sure you call `wp_head()` in your pop-up box, or if you can't do that (pop-up is not a html document), then just call the function directly, like:
if(function_exists('process_postviews'))
process_postviews();
// the_content(); ? | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "posts, views"
} |
Clean URL link for page without number
This is probably a really noob question, but I can't figure out how to change it. I've created a page called "Photos" and my url link shows:
What's with the **-7** and how do I remove this so it is just _photo_? | This is because your site already has a post or page (6 in your case) with the slug "photo."
They might be in the trash, or pending as drafts, or whatever ... but WordPress automatically appends number to prevent name conflicts.
So go through your site, and figure out which other pages are trying to use the "photo" slug and change their slug to something else. Then you can re-edit your other page to change its slug to just `photo` rather than `photo-7`. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 1,
"tags": "pages, urls"
} |
Function to check whether the user is at the top level of the network?
I need a conditional to check to whether or not to execute code at the top level of network admin pages: `/wp-admin/network` | if(is_super_admin() && is_network_admin()){
// do network admin only code
}
<
< | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "multisite"
} |
Blank page for edit.php
I get a blank page on /wp-admin/edit.php after change the number of post to display. The bug is due to the PHP memory, but on my hosting I have no possibility to change this value.
!enter image description here
How to reset the number of post to display on the edit.php page please.
Thanks you | In your usermeta database table, there will be rows containing a meta_key of `edit_post_per_page` find the row that matches your username and then either change the value to something more sensible, or delete that row to restore the default of 20. Or you could delete all rows in that table with that key, it's not a critical value and it will not break anything if removed.
!enter image description here
Then I would take a look at your plugins to see which ones are consuming the most memory. There are plenty of free profiler plugins out there, I suggest you try a variety of them ( but not all at the same time ) | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "wp admin, memory"
} |
running arbitrary php files
I have a hostgator wordpress site. My friend wrote two small php scripts to help us with a medial task we do a lot in our work, but he is currently hosting this script on his server; I want to host it on our official server.
Is there a way to straight-up ftp this folder containing
1. two php files
2. a larger js file
3. a subfolder of multiple images
directly to my site and have it work? Every time I try to directly access the php file, wordpress automatically redirects to home ( This is probably a very good security measure, but is there some way to whitelist these scripts to run without modifying them at all? | WordPress offers a dedicated API for your need: the Plugin API. So (let) write a plugin, which is really easy. Then you can use the extra code probably without conflicts. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "php"
} |
What is the server IP comment hack
this is my first question about wordpress, because i don't know much about wordpress.
i have installed AntiSpam bee in my wordpress blog. And i got comments which marked as spam with the reason `Server IP`, that i got first time.
But i got shocked when i see that the comment don't had any **Email Address** .
but as i know that without any user name and email no one can send any comment to any post. Please someone help me to telling that what exactly happen or what i did wrong. | You get this if `$_SERVER['REMOTE_ADDR']` of a ping/track back doesn’t match the IP address of the URL the ping back comes from allegedly.
Let’s say someone claims to send a ping back from `example.com` but the request IP and the server IP for `example.com` are different – the ping back is marked as spam.
The documentation is not very clear about this, but a look at the source code told me everything ~~I~~ you wanted to know. :) | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 2,
"tags": "comments"
} |
Making a plugin only available on the front-end for the logged in super admin
I made a little plugin that enqueues 1 .js file and 1 .css file into a theme's front-end. All it does it load a grid on top of the theme so I can visualise the design.
If this plugin was activated on a live site, is it possible that only I (the super admin) can see the JS and CSS files included onto the front-end?
All I have inside the plugin file is this:
function load_grid() {
wp_enqueue_style('grid_css', plugins_url('/lib/css/grid.css', __FILE__) );
wp_enqueue_script('grid_js', plugins_url('/lib/js/grid.js', __FILE__), array('jquery') );
}
add_action('wp_enqueue_scripts', 'load_grid'); | function load_grid() {
if ( current_user_can( 'level_10' ) ) {
wp_enqueue_style('grid_css', plugins_url('/lib/css/grid.css', __FILE__) );
wp_enqueue_script('grid_js', plugins_url('/lib/js/grid.js', __FILE__), array('jquery') );
}
}
add_action('wp_enqueue_scripts', 'load_grid'); | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "plugins, plugin development, wp enqueue script, capabilities, wp enqueue style"
} |
single page wordpress
I like wordpress as a CMS and I think it's got a lot there with it's vast plugin library however the front end, dare I say it is a bit out of date.
I don't like the system of old going page-to-page and would prefer a single-page site powered by JSON/AJAX. I've used wordpress to make simple client sites but when it comes to anything more impressive, the system of templates which wordpress has is a bit lacking.
I'm used to using Backbone.js and Knockout.js for frameworks and require.js for module loading. I'm looking for a plugin or source reference for effectively removing the wordpress front end and using CRUD/REST and Javascript to build single page dynamic sites.
Can anyone point me in the right direction? | There's nothing stopping you using AJAX for a singlepage website that loads in other pages dynamically rather than going to a whole new page. I would advise you build the site without the AJAX and then add AJAX on top so that everything degrades gracefully should an error occur or if javascript is turned off.
So assuming that you've now got a site that works almost as you intend but without the AJAX, you can easily jsut wrap all your content in IDs that jquery could pick up and request URLs on hyperlinks via js requests instead of letting the browser handle it.
That's tbe answer in its most crudest form.
You can adjust your templates too so that if the request was made by AJAX they only return the relevant content rather than a full blown templated page:
<
Alternatively you can implement arbitrary AJAX callbacks, here's a list of articles on how to write use and extend the AJAX callbacks WordPress provides:
<
<
<
<
<
<
<
< | stackexchange-wordpress | {
"answer_score": 8,
"question_score": 3,
"tags": "javascript, single"
} |
Notice: attribute_escape is deprecated
I have WP_DEBUG set to ON to show errors and notices. Of all notices the one that is bothering me is `Notice: attribute_escape is deprecated since version 2.8! Use esc_attr() instead. in /Users/john/Documents/htdocs/wp-includes/functions.php on line 3467`. I started commenting the code to find which function or statement was generating these notices. To my surprise these notices were thrown by `wp_head()`, `echo get_the_title()` — The core Wordpress functions. I switched the theme to twentyeleven where the problem does not appear at all.
So, I'd like to find out why these core functions are throwing notices in my theme and what can I do to debug, isolate and resolve these?
Regards, John | This proves that the problem isn't core:
> I switched the theme to twentyeleven where the problem does not appear at all.
Core functions are not throwing those notices. Your Theme is calling the deprecated function(s) somewhere - perhaps in a filer callback for `the_title`.
Search your Theme files to find the culprit. Start in `functions.php`.
p.s. what Theme are you using? | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "debug"
} |
Upload .doc to blog
All my blog contents are well prepared in MS Word. Some contents have image flow chart.
On copying the contents from Word doc, i am not able to copy the Images.
How should i copy both contents and images from word doc to the Blog?
Or
Is there any way to upload each doc file which will directly extract the contents including images from Word doc to the Wordpress. | The better way would be to use Windows Live Writer. It's a Microsoft product that's part of the Windows Live Essentials suite.
This program allows you to copy-paste content from a Word document, or just build the post out as you would in Word. But the advantage is that it can also talk directly to your WordPress site using XML-RPC.
This means you can write your post locally, format images locally, and get everything set up locally _just as you would in Word_. Then you hit publish, and Writer will push the content _and your images_ to your site. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "images, uploads"
} |
.sub-menu or .children?
I'm developing a theme using a test installation (using InstantWP), but when I upload it to a staging site, for some reason the nav menu looks inflated. After looking at the source, it turned out to be that for some reason my test install uses the class `.sub-menu` while the staging install uses `.children`.
Both installs are fresh installs of 3.3.1 with the exact same plugins installed. Why would there be such a discrepancy between the two installs? | What One Trick Pony said; look in Appearance > Menus on both sites and check if the menu has been populated. If so, check to see if the Theme Location has been set and saved. If they are different that may be what's causing different menu structures to be rendered.
Let us know how it goes - good luck! | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 1,
"tags": "theme development, navigation"
} |
Can you set up a wordpress (multi-site) network to work across multiple hosting accounts?
I would like to manage multiple sites running as part of a single wordpress network, but I don't want to personally host each of the individual sites. I don't mind if my database holds all the tables for each site, but I don't want to be the sole host for all the files, etc for each site. Is there any way to do this? | A multi-site network only has one set of files:
* There is only _one_ WordPress installation that is shared among the various sites.
* There is only _one_ database shared among the various sites.
The database and WordPress files don't need to be on the same physical machine, but they need to have access to one another.
The WordPress files _must_ be on one machine (hosting account).
The database can be spread across multiple database servers using sharding (See the SharDB plugin for an example).
If you want your various sites on different hosts, then you really need to have different WordPress installations. _Read: Not multi-site._
There is a service available for managing multiple, standalone sites called WP Remote. You might want to look into that ... | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 2,
"tags": "multisite"
} |
How to get wordpress nav menu outside of wordpress system?
I want to get a specific wordpress nav menu as a list in my custom php page outside of wordpress.
How to do that? | There are a few ways, here's one:
// no theme output
define('WP_USE_THEMES', false);
// initializes the entire Wordpress
require '/path/to/your/wp/wp-blog-header.php';
// here you print your menu
wp_nav_menu('your_theme_menu_location');
Even if theme output is disabled, the theme's functions.php should still be loaded (and menu locations registered).
You should cache the HTML somewhere within your script, because loading WP just to show a menu can be slow.
* * *
see < | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 2,
"tags": "menus, customization"
} |
How to manipulate attributes of url-less dropdown item in a the custom wordpress menu?
I need to change the color of some custom link elements in dropdown of my wordpress custom menu here. There 3 items in my dropdown that dont have any url associated with them:
* Air Duct
* Chimney
* Dryer Vent
They will be just the headers for other dropdown items below them.
I need to be able to change their attributes such color, font-family and size, etc.
I was trying to create menu-item-type-custom and menu-item-object-custom and even menu-item-#### classes, but it didn't do it... :( Please help! | Enable the `CSS Classes` (Screen Setting -> Flag CSS Classes) and use it to customize every menu item that you want to be styled in a different manner.
You must use a Custom menu, of course. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "menus, css"
} |
Sanitizing post content for use in an email
I'm sending the content of a custom post type in a plain text email (it's to send competition entries to a panel of judges), so I need to make sure that `$post->post_content` is correctly sanitized first.
Is there a filter I can use for this, or if not, what sanitization do I need to do?
Update: I've just found `wp_strip_all_tags` in `wp-includes/formatting.php`, is this what I need? | You will want to use `sanitize_email();` as follows:
return( sanitize_email( $email ) );
Here is the Codex link so you have it: <
Cheers! | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 3,
"tags": "custom post types, email, the content, sanitization"
} |
How to get Category Id from Post Id ?
I need to get any post category id from the post id(Not for current) Post. How can i ?
Thanks | You can try this code for getting category id from post id:
global $post;
$category_detail=get_the_category( $post->ID ); | stackexchange-wordpress | {
"answer_score": 7,
"question_score": 3,
"tags": "posts, categories"
} |
How to display meta box data using "Meta boxes as needed"
I have been following this post exactly: < and have everything working in the backend but when I try to use `echo get_post_meta($post->ID, 'songs', true);` in my template all that is shown is `Array`. Any ideas? I would appreciate it. | You might wish to try;
<?php
$mykey_values = get_post_custom_values('my_key');
foreach ( $mykey_values as $key => $value ) {
echo "$key => $value ('my_key')<br />";
}
?>
Where my_key would be equal to songs.
Another example of what I might do in a situation where I am dealing with multiple values;
<?php
global $post;
$meta = get_post_custom_values($post->ID, 'songs', true );
foreach ( $meta as $value ) {
echo $value . "<br />";
}
?>
Update: Try the following instead, which will cycle through each title and track of your 'songs' post meta.
global $post;
$meta = get_post_meta($post->ID, 'songs', true );
foreach ( $meta as $key => $value ) {
echo $value['title'] . "<br />";
echo $value['track'] . "<br />";
} | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "metabox, post meta"
} |
How to reference same column name but different table in custom db query
I use `wpdb` to connect to a custom db, then I use the following query:
$my_row = $wpdb_c->get_results(
"SELECT Employee.Name, Area.Name, Area.Region"
. " FROM Area INNER JOIN Employee ON Area.ID = Employee.Area_ID"
. " WHERE Employee.ID = " . get_the_ID()
);
How do I refer to each of the `Name` columns from the `Employee` and `Area` tables? I tried `$my_row[0]->Area.Name` but it only returned the string `'Name'`. | Modify your query and use the SQL alias `as`:
$my_row = $wpdb_c->get_results("SELECT Employee.Name as Employe_Name, Area.Name as
Area_Name, Area.Region as Area_Region FROM Area INNER JOIN Employee ON Area.ID =
Employee.Area_ID WHERE Employee.ID = " . get_the_ID());
Then in your code use:
$my_row[0]->Area_Name | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "query, wpdb"
} |
Should we use get_template_part() in functions files instead of include_once?
I'm using the theme-check plugin to check my theme for errors and recommendations, I'm using get_template_part() in theme files like header.php and index.php but in functions.php I'm using include_once() theme-check is not pointing at these, it's pointing at include_once used in a widgets.php file which is included in functions.php
my question is should we use get_template_part() instead of all include_once() and include() or just use it for getting frequently used markup only ? I know it's only recommended to use get_template_part() but I like to follow best practices and recommendations.
thanks in advance. | Your `functions.php` doesn’t create output, so you should use `locate_template()`.
Example:
locate_template( 'php/functions.nav-menu.php', TRUE, TRUE );
You’ll find this function in `wp-includes/theme.php`. The first parameter is the **file path** relative to the theme root, the second tells WordPress to **load** it (or not), and the third to load it just **once**.
Now a child theme can override the file by just placing a file with the same name to the same place in _its own_ theme root. | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 10,
"tags": "theme development, include, get template part"
} |
how does get_term_by know which term to return when the same term appears twice in a hierarchical taxonomy?
This is from the codex.
<?php get_term_by( $field, $value, $taxonomy, $output, $filter ) ?>
Suppose I have a taxonomy system as follows;
taxonomy: "healthy foods" and it's a hierarchical taxonomy and your hierarchy goes exactly like this;
healthy foods
fruits
red ones
green ones
veggies
red ones
green ones
and you use the `get_term_by` function as follows;
get_term_by("name","red ones","healthy foods")
Do you get the veggies or the fruits? | `get_term_by()` just returns the first matching term, 'first' meaning some internal order in MySQL.
If having multiple terms with the same name matters in your case, don't rely on `get_term_by()` alone. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "custom taxonomy, terms"
} |
Fatal error: Call to a member function add_rewrite_tag() on a non-object in /wp-includes/taxonomy.php on line 333
I get this error while trying to load wordpress in a smarty template. But when I visit wordpress I dont get that error any where.
the code I use to load wordpress is :
{php}include $_SERVER['DOCUMENT_ROOT'].'/wordpress/wp-load.php';
get_header();{/php}
The Error : Fatal error: Call to a member function add_rewrite_tag() on a non-object in /wp-includes/taxonomy.php on line 333 | Found the solution. just add this code before including wp-blog-header.php.
global $wp_rewrite;
source: < | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "customization, rewrite rules"
} |
What is the function to get plugin base url in multisite?
I'm using this function `plugins_url()`.
But it always echoes main site url even in subsite.
So i'm getting ajax errors like `Domains, protocols and ports must match.`
Lets say my main domain name is `blahblah.com` and my subdomain is `mysubdomain.blahblah.com`
Is there any function available that returns `mysubdomain.blahblah.com/wp-content/plugins` instead of `blahblah.com/wp-content/plugins`?
Thanks
## Update:
As of now i'm using like this.
home_url( '/' ).'wp-content/plugins/'.str_replace(basename(__FILE__),"",plugin_basename(__FILE__))
Here `wp-content/plugins/` text hard coded.
So any other alternative method there? | The `plugins_url()` function is designed to work in WordPress Multisite. Here is an example of its proper usage:
>
> <?php
> echo "<img src="' .plugins_url( 'images/wordpress.png' , __FILE__ ). '" > ';
> ?>
>
>
> If you are using this function in a file that is nested inside a subdirectory, you should use PHP's dirname() function:
>
>
> <?php
> echo "<img src="' .plugins_url( 'images/wordpress.png' , dirname(__FILE__) ). '" > ';
> ?>
> | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 3,
"tags": "plugins, plugin development, multisite, functions"
} |
What is Global Wordpress Objects?
I was trying to load wordpress in a smarty template and i have got a lot of errors that has the same origin "Fatal error: Call to a member function the_function() on a non-object".
The solution to such error is by declaring the wordpress global objects before loading wordpress like this:
global $wp_rewrite;
Is there is a list of these objects that I can use to declare all of them so I don't get any of these errors again? | As I've mentioned in the comments - you shouldn't need to modify / touch WordPress globals directly. It seems you are getting the errors because you are trying to load WordPress within Smart - this is a bit of a hacky approach.
I've not used Smarty at all, but WordPress has its own way of handling templates and trying to load WordPress within another framework is not going to be without its difficulties. Instead, you might consider this plug-in: < which allows you to use your smarty template with WordPress. To quote the plug-in's readme:
> Smarty for WordPress is the first plugin which incorporates a complete distribution of the Smarty template engine as a WordPress plug-in. You embed your Smarty template file by using a WordPress short code with the Smarty template file name and any variable which you want to be passed to your Smarty template file. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "customization, wp load.php"
} |
Add default Backgrounds
Is there code or a plugin that would make it possible to add default backgrounds, like you can with default headers in Twenty ten. Seems like the same frame work for backgrounds and headers. | There's no default way to do that yet, though there is a Trac ticket. I found this (untested) that may work for you: <
It's also worth noting the 3.4's new way of defining a default background (still just one, though).
# Edit
Here's the code:
<?php
function wpse48332_setup_theme() {
// Add support for custom backgrounds
add_theme_support( 'custom-background', array(
// Background color default
'default-color' => '000',
// Background image default
'default-image' => get_template_directory_uri() . '/images/background.jpg'
) );
}
add_action( 'after_setup_theme', 'wpse48332_setup_theme' );
?>
(Note that you can also define front end, admin, and preview style callbacks, as well.) | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 6,
"tags": "theme development, images"
} |
How can I externally retrieve a post's custom sized image
I would like to be able to display my last X wordpress posts in the sidebar of my phpBB3 forums.
Since I can't use WP's functions (because trying to use WP's functions into phpBB3 generates conflicts), I have to use a hand-made php script.
So, my question is, has anyone a custom php script that would enable me to retrieve, from a given wp post ID, it's first image in a given size* ?
* Knowing that each of my wordpress post may have several images, and that I generate several custom image sizes when adding an image to a post.
* The size I want is 300x100 and is cropped, so I guess that if i can retrieve the image's filename, I just would have to add -300x100.jpg at the end to get the correct filename.
Cheers ! | Try RSS, like Magpie RSS - PHP RSS Parser or Google Feed API — Google Developers to pull posts without using WP's library.
Google Groups has forum posts on pulling images, and someone at SO found a way to pull images from Magpie: < There are lots of other resources via Google. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "images"
} |
Does Wordpress have a "Form API"?
I do most of my development in Drupal. However I'm working on a Wordpress site and I need to make a form.
Which got me thinking: Is there something like a Form API for WordPress like there is in Drupal? Is there a way to add a standardized form by using PHP? | No, but it should ;)
There are several custom field class's (backend).
* wpAlchemy : <
* Meta Box Script: <
* My-Meta-Box: <
* meta-box-class: <
* Meta Boxes Class: <
For front-end forms, you probably best off with a plugin in Eugene Manuilov's link. | stackexchange-wordpress | {
"answer_score": 8,
"question_score": 12,
"tags": "metabox, forms, api"
} |
Add paragraph tags to comments
The line breaks on my comments are not being considered. I've inspected the elements in google chrome and it seems that wordpress is not adding paragraph tags `<p>` to them, while in the body text it does.
The comments.php in my template has the following snippet:
<ol class="commentlist">
<?php wp_list_comments(); ?>
</ol>
No options of wp_list_comments() seems to be related to this.
Also, in the file `default-filter.php` I have the line
add_filter( 'comment_text', 'wpautop', 30 );
So I don't understand why it's not adding the tags.
Is anyone facing the same problem? | Thanks to @toscho I've found the problem.
Crayon Syntax Highlighter 1.9.1 seems to have a bug. While it's not fixed, one workaround that is reasonable for me is unchecking the "Allow Crayons inside comments" option. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "comments"
} |
Can't give tags rels
In my Wordpress post I click on edit post and skip over to the html editor tab and click on it. I have a pre on that page and when i give it a rel and publish its all fine but when I skip back over to visual editor it just takes out the rel attribute. | function extend_tinymce( $values ) {
$elements = 'pre[id|class|title|rel]';
if ( isset( $values['extended_valid_elements'] ) ) {
$values['extended_valid_elements'] .= ',' . $elements;
} else {
$values['extended_valid_elements'] = $elements;
}
return $values;
}
add_filter('tiny_mce_before_init', 'extend_tinymce');
The above snippet is what I use for example, of course you can extend this beyond id, class, title, rel, to things such as height, width, style, name, etc... | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "posts, visual editor, html editor"
} |
Redirecting home to /wp-login.php?action=register
As I'm currently using WordPress only as a registration platform for GlotPress I was wondering if it would be possible to somehow redirect users visiting ` to `
` being my WordPress installation folder (and ` being my GlotPress installation folder) | Place this in a plugin or in functions.php
if(is_home()){
wp_redirect(site_url('/wp-login.php?action=register'));
} | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "redirect, translation"
} |
Sanitation needed for WP_Query or get_posts calls?
Just wanted to get a straight answer on this: when submitting query_vars to a call to get_posts or WP_Query, is sanitation needed or does WordPress already take care of that? | No. Parameters given to the `WP_Query` object only need to be escaped for the database query - this is handled by WordPress. | stackexchange-wordpress | {
"answer_score": 7,
"question_score": 5,
"tags": "wp query, get posts, sanitization"
} |
Big side banners
I would like to have a big header side advertisements like this: What is the best way to achieve that?
!enter image description here | Register sidebars for the banners, then use the text widget to place your code in it. The default widget will strip some HTML code, so you may want to use something less invasive like my Unfiltered Text Widget. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "widgets, css"
} |
sort post types by amount of views
I have a custom post type that I want to do a type of news feed for, but I only want to show the ones with the most views. I know I can do a query for an "archive" of my post types, but my question is "how to sort the query by views"? | WP post views plugin already does this job very well.
So just install that plugin , then use function like this
<?php if (function_exists('get_most_viewed')): ?>
<ul>
<?php get_most_viewed('custom post type name',20); ?>
</ul>
<?php endif; ?>
For more info, check this FAQ page | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "custom post types, sort, views"
} |
Getting links to work the same on development and production
I am working on a website where I am specifying links to pages within my site in other pages.
I am using the same permalink post name structure i.e. < on both development and production and I am using /index.php/sample-post/ to link to a specific blog. This works on production but not on development.
My development machine's wordpress install is under a directory called wordpress and is running off a URL <
On development for some reason when I specify /index.php/sample-post the wordpress part of the site url is absent. This only seems to happen with posts and not pages.
As far as I know /index.php/ refers to the site url which should be < unless I am mistaken. Moreover I would like to know if there is any alternative way to specify absolute URLs in wordpress and get around this problem.
Thanks in advance. nav | Managed to work this out. I have posted the step on stackoverflow.
Hope it helps someone. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 2,
"tags": "permalinks, site url"
} |
Grabbing specific content
Right now I'm doing this (pseudo code)
posts = content_type("special_stuff");
$i = 0;
$n = 5;
$while(have_posts) {
if($i == $n) {
// print the content
}
++$i;
}
This is what I'm doing to always get the `n`th item. I'm sure there is a better way, but I'm kind of a WP noob.
Related:
1. (this question) How do I grab the nth element of a content type? eg. always getting the 1st or 5th most recent element from the db.
2. List item
How do I do #1 based on content id? | First of all learn WP_Query class.
Answering on questions:
> (this question) How do I grab the nth element of a content type? eg. always getting the 1st or 5th most recent element from the db.
$query = new WP_Query( 'post_type=special_stuff&posts_per_page=1&paged=5' );
> List item
// The Query
$the_query = new WP_Query( $args );
// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post();
echo '<li>';
the_title();
echo '</li>';
endwhile;
// Reset Post Data
wp_reset_postdata(); | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 1,
"tags": "content, recent posts"
} |
Proper way to include stylesheet for panels
What is the proper way to include a stylesheet with my options panels in wp-admin for a given plugin or theme. In other words -- the stylesheet that styles the panels.
I mean, in my panel template code, I'm doing something like...
<style type="text/css">
@import url("../wp-content/plugins/myplugin/panels/style.css");
</style>
...but suspect that this won't work on some installs of WordPress because of paths and so on, and might not work in the future of WP gets a wild hair and wants to rename wp-content with something else. | The _best practice_ method of enqueueing admin stylesheets is to **hook into your appearance page's specific hook**, using the `admin_print_styles-{hook}`, where `{hook}` = `{admin_page}-{menu_slug}`.
I'll assume:
1. This is a Theme
2. You are properly using an _appearance_ page, via `add_appearance_page()`
3. Your `$menu_slug` is `wpse48416-settings`
The hook, then, is: `admin_print_styles-appearance_page_wpse48416-settings`:
<?php
function wpse48416_admin_style(){
wp_register_style( 'wpse48416_admin_css', get_template_directory_uri() . '/css/admin.css' );
wp_enqueue_style( 'wpse48416_admin_css' );
}
add_action( 'admin_print_styles-appearance_page_wpse48416-settings', 'wpse48416_admin_style' );
?>
For a Plugin, you simply need to use the correct `{page}` string, depending on which admin menu function you use to register your settings page, e.g. `settings_page` for `add_settings_page()`. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "plugin development, css"
} |
How can I input a single right-to-left paragraph (Hebrew) into an English page/post?
I have an English blog. In one of the pages I want to include a Hebrew paragraph between two English paragraphs (I expect the English text to be left-aligned and the Hebrew text to be right-aligned). I can get the Hebrew text to be right aligned, but not in a right-to-left way (e.g. the period at the end of the sentence appears to it's right instead of its left).
I tried pasting formatted text from Microsoft Word, but it doesn't work (the pasted text changes from right-to-left as it was in Word to the screwed-up form I get on WordPress if I type it myself).
I do not want the admin interface to change, I do not want my entire blog to change to right-to-left. Only a paragraph.
How can I achieve that? The site is < | You can add a hebrew shortcode to wrap around your hebrew text and then use the CSS2 direction attribute to indicate the text direction.
e.g.:
In your themes functions.php:
function hebrew_shortcode( $atts, $content = null ) {
return '<p lang="he" DIR="RTL">' . $content . '</p>';
}
add_shortcode( 'hebrew', 'hebrew_shortcode' );
Your content:
> [hebrew]Hebrew styled right to left text![/hebrew]
edit: I've updated to use the dir html attribute ( spec docs said do nto sue css to indicate right to left ) and to use a p element instead | stackexchange-wordpress | {
"answer_score": 9,
"question_score": 4,
"tags": "text"
} |
getting a js file for one page
wp_register_script('SliderViewer', '/js/SliderViewer-1.2.js');
wp_enqueue_script('SliderViewer');
get_header();
however, `mydomain.com/js/SliderViewer-1.2.js` doesn't exist.
My js is in the ftp at
thewebsite -> wp-content -> themes -> BLANK-Theme -> js
What's the path of that? Thanks- | You're registering/enqueueing your script wrong. You should register/enqueue in your theme's `functions.php` file instead of inside the header/page.
Also, you need to use your theme's directory ... which will be along the lines of `mydomain.com/wp-content/themes/BLANK-Theme/js/SliderViewer-1.2.js`.
Use this code in `functions.php`:
function my_scripts_enqueue_method() {
wp_enqueue_script(
'SliderViewer',
get_template_directory_uri() . '/js/SliderViewer-1.2.js'
);
}
add_action( 'wp_enqueue_scripts', 'my_scripts_enqueue_method' );
This will enqueue _and_ register your script, and ensure that you're using the appropriate directory for your theme in the process. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 1,
"tags": "wp enqueue script, wp register script"
} |
Switching MultiSite installation from HTTP to HTTPS
I installed MultiSite with the URL set as _ , but now I want to force all requests to go over HTTPS, so I'm trying to change the URL to be _ I've gone through the database and updated all the `siteurl` and `home` values to have _https_ , but the site still loads over HTTP, instead of being redirected to HTTPS.
I know that I could setup some htaccess rules, but that's prone to errors. In regular installations WordPress will automatically redirect all requests to the canonical URLS defined in the `siteurl` and `home` settings, so I'm assuming that MultiSite does too. | There are plugins to set the site to SSL. Why not use one of them?
And you do have an SSL certificate installed and active? | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 11,
"tags": "multisite, ssl, site url, https, home url"
} |
flexible rewrite 'ramble' URLs with Wordpress
I want to access my post with id 17 like this:
<
In other words, the id shall decide, everything thereafter may (or may not) be the slug or anything else. Much like these links leading to the same page (many other sites do the same):
* <
* <
I tried to define a rewrite-rule like this near the top of my .htaccess:
RewriteRule ^archives/(\d{1,12})(?:/.*) archives/$1 [NC]
This _almost_ works, i.e. goes to the right page, but get's me a page-not-found then, because wordpress looks at PATH_INFO again (I think) and states `$query_string` now is `string attachment=moot-bla-foo-ramble`
I do not want to do a 301 redirect.
My favourite or course, if such thing existed in Permalink Settings:Custom Structure
/archives/%post_id%/%wildcard%
Albeit that would make the 'ramble' mandatory, so even better...
/archives/%post_id%(/%wildcard%)?
wishful thinking, I guess. | You shouldn't use the htaccess instead you should use the WordPress APIs
e.g.
function custom_rewrite( $wp_rewrite ) {
$feed_rules = array(
'archives/(\d+)(?:/.*)+' => 'index.php?p='. $wp_rewrite->preg_index(1)
);
// ( array merge must be done this way, to ensure new rule comes first )
$wp_rewrite->rules = $feed_rules + $wp_rewrite->rules;
}
// refresh/flush permalinks in the dashboard if this is changed in any way
add_filter( 'generate_rewrite_rules', 'custom_rewrite' ); | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 2,
"tags": "permalinks, url rewriting, urls, rewrite rules"
} |
How to retrieve $_GET variables from rewritten URLs?
I need to receive some special $_GET parameters for a custom page I'm making, i know how to receive this through a simple $_GET like mysite.net/products/?id=1 , but I wanted to use the URL style of my WordPress like mysite.net/products/1.
How to retrieve $_GET variables from rewritten URLs? | To be added on `init`:
To register your custom variable ('id' in the question)
add_rewrite_tag('%mycustomvar%','([^&]+)');
To create a re-write rule:
add_rewrite_rule('^product/([0-9]{1,})/?','index.php?p=4&mycustomvar=$matches[1]','top')
4 is the id of the 'product' page. You will need to flush rewrite rules once after adding these (go to Permalink settings page)
You can get the value of `mycustomvar`: `get_query_var( 'mycustomvar' )`.
See Codex for:
* `add_rewrite_tag`
* `add_rewrite_rule` | stackexchange-wordpress | {
"answer_score": 9,
"question_score": 8,
"tags": "url rewriting, page template"
} |
Shortcode always displaying at the top of the page
I'm using a shortcode to pull in different loops via the loops-name.php. For some reason it is always at the top of the page. I googled it and using echo instead of return causes that problem but with my code I am not using echo. Here's the shortcode:
// setup the shortcode for use
function friendly_loop_shortcode( $atts, $content = null ) {
extract( shortcode_atts( array(
'category' => '',
'module' => ''
), $atts ) );
include(locate_template('loop-'.$module.'.php'));
}
Any idea why this is happening? | You can buffer the output like this:
ob_start();
include(locate_template('loop-'.$module.'.php'));
return ob_get_clean();
EDIT. I tried this, worked fine.
function friendly_loop_shortcode( $atts, $content = null ) {
extract( shortcode_atts( array(
'category' => '',
'module' => ''
), $atts ) );
ob_start();
include(locate_template('loop-'.$module.'.php'));
$output = ob_get_clean();
//print $output; // debug
return $output;
}
if (!is_admin()) {
add_shortcode('test', 'friendly_loop_shortcode' );
} | stackexchange-wordpress | {
"answer_score": 23,
"question_score": 20,
"tags": "shortcode"
} |
booking form with availability calendar
I need a booking system with availability calendar for my website, something simple with some basic forms. I want to be able to insert for each post a "book now" button with an availability calendar for each post(apartment, house)
I've found this plugin
It's nice and simple but It doesn't have an availability calendar and online payment support. So, could you recommend me something which can work with my requirements ? Thanks! | Try Wordpress Booking Calendar, it's quite complete! | stackexchange-wordpress | {
"answer_score": 1,
"question_score": -1,
"tags": "plugins, plugin recommendation"
} |
Media Custom Fields - get a value with PHP
How to get a value of a field set with Media Custom Fields (programmatically)? | As taken from :
<
> **How does this plugin handle my data?**
>
> Media items are stored in WordPress just like regular posts. This enables us to use native WordPress functions to store and retrieve your custom fields. Due to this, your data is stored in a very future-proof way, in the postmeta table of the WordPress database.
So you would do it the same way you would do it for a post or page using `get_post_meta`, but you would pass the media attachment ID in as the post ID | stackexchange-wordpress | {
"answer_score": 2,
"question_score": -1,
"tags": "custom field, media, media library"
} |
Modal window from within Wordpress admin
How can get a modal window to work from within the wordpress admin?
I want to create a modal window that will work from a meta box within the wp-admin.
Any ideas? | Give the anchor a class of thickbox and make sure that the thickbox script is enqueued on your admin page using `add_thickbox`
add_thickbox();
and
<a href="your url" class="thickbox">click here</a>
You can see what `add_thickbox` does here:
< | stackexchange-wordpress | {
"answer_score": 21,
"question_score": 20,
"tags": "admin, wp admin"
} |
How to get CGI variables?
I need to do two things:
1. Add a CGI variable (say filter=21) to the current query and make a link to this modified URL.
2. Fetch the value of CGI variable "filter".
How to do that in WordPress? | First off, these aren't CGI variables, they're **query string arguments**.
WordPress, by default, will remove any query arguments that it doesn't recognize. So you need to register them with WordPress and then pull them back out of the query.
**First, add your new query variable:**
function wpa_48528_vars( $vars ) {
$vars[] = 'filter';
return $vars;
}
add_filter( 'query_vars', 'wpa_48528_vars' );
**Now, get the data back out:**
function wpa_48528_get_filter() {
global $wp_query;
if ( array_key_exists( 'filter', $wp_query->query_vars ) ) {
return $wp_query->query_vars['filter'];
}
return '';
} | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "urls, variables"
} |
wordpress get_post_meta / the_meta to output custom field value
What I'm trying to do is quite simple: I want to add a custom field named 'Button' to each post that will show a button (image) on the page with the value as its link.
It's basically a button that will show on every post, the link that the button points to will be entered in the value field of the custom field.
This is the code I used in single.php:
<div class="button">
<a href="<?php get_post_meta($post->ID, 'Button', true); ?>">
<img src="<?php echo get_template_directory_uri() . '/images/button.png'; ?>" alt="link" />
</a>
</div>
The problem is that the output of the value field doesn't appear. The link that supposed to be on the button image is not in place. Instead the button links to the post.
This is the website in question: < | You need to echo `get_post_meta()`, like this:
<div class="button">
<a href="<?php echo get_post_meta($post->ID, 'Button', true); ?>">
<img src="<?php echo get_template_directory_uri() . '/images/button.png'; ?>" alt="link" />
</a>
</div> | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "custom field, post meta"
} |
Selecting a post in Dashboard
How to make in the admin's dashboard a <select> with the list of all posts of specified post type?
I need this in order to save a post ID with `set_option()` call.
How to do this? | Use `wp_dropdown_pages()` to create the drop down. It accepts an `post_type` parameter.
To avoid collisions with plugins filtering this function you may use `walk_page_dropdown_tree()` and build your own `select`. See this post for a code example. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "custom post types, admin, wp admin"
} |
Reblog WordPress to another WordPress?
1.Is there any way to reblog only the excerpts of WordPress posts to another WordPress with the featured image(option to choose the size of the image we prefer) and link to the WordPress site to see the full post from specific category/ies or tag/tags?
2.Will it cause me any problem to my page rank and the Google search results if I do something like this? | 1 - RSS is the best way. See FeedWordPress | simple and flexible Atom/RSS syndication for WordPress and WordPress › SimplePie Plugin for WordPress « WordPress Plugins and Developer's Guide - Google AJAX Feed API - Google Code
2 - Probably | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "excerpt"
} |
is_taxonomy is deprecated. What's the alternative?
Now that `is_taxonomy($taxonomy)` function deprecated how do I know if a taxonomy exist? What's the alternative?
On a second note, the codex for `wp_insert_term()` says that if the taxonomy does not exist, an error is fired. Here, the "if taxonomy exists" part is ambiguous to me. Does that mean if the taxonomy has currently been registered with the registered_taxonomy or does that mean there is at least one term in the `wp_term_taxonomy()` table that's been associated with that taxonomy?
And my 3rd question final question is how do I catch an error when an error is raised by the `wp_insert_term()` function?
Would this work?
if (list($term_id,$taxonomy_id) = wp_insert_term(...)):
else:
//error here?
endif; | See Codex page for `is_taxonomy`
> This function is deprecated as of Version 3.0. Please use taxonomy_exists instead.
`wp_insert_term` uses `taxonomy_exists` to check if the taxonomy exists. This means if the taxonomy is a _registered_ taxonomy. (It would be odd if `wp_insert_term` only you allowed to add a term to taxonomies with existing terms :) )
To catch an error you can use `is_wp_error`. E.g.
$result = wp_insert_term(...);
if ( is_wp_error( $result ) ) {
$error_string = $result->get_error_message();
echo '<div id="message" class="error"><p>' . $error_string . '</p> </div>';
}else{
list($term_id,$taxonomy_id) = $result;
} | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "taxonomy, register taxonomy"
} |
Does wp track views for posts?
I want to do a query and sort posts by views. Is this possible? I'm not even sure where to start.. | WordPress does not maintain post view count by default.
But you may find the following post helpful.
Does wordpress have a post hit counter?
You may also have a look on the WP-PostViews plugin.
Many thanks. | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 0,
"tags": "wp query, sort, views"
} |
How to include own css on wordpress tinymce editor?
I have added some text on tinymce editor on load.
(Every time you click on Add new the tinymce editor load with this text.)
but problem is how to enable css class which are using in default text.
Thanks | Use `add_editor_style`
e.g.: functions.php
add_editor_style('custom-editor-style.css');
< | stackexchange-wordpress | {
"answer_score": 11,
"question_score": 7,
"tags": "customization, css, tinymce, editor, add editor style"
} |
Set Post Thumbnails in Percents
I've built this responsive site on WordPress and got a little curious as to how I can set the post thumbnails in percentages. Any help would be much appreciated. | This is not possible, images must have real absolute sizes :)
A post thumbnail is essentially a different sized version of the image. While you can calculate how much for example 70% of 1024 is, and genereate a ~700px wide image, you cannot do this for each of your visitors. It would kill your host's CPU...
The closest thing you can do is to browser-resize images to fit their container:
img{
max-width: 100%;
height: auto;
} | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "post thumbnails, responsive"
} |
How to take large file uploads from users the right way
I'm using gravity forms to take mp3 submissions but doing it like that seems to be extremely intensive on my site especially when multiple people are doing it one time and streaming the content aswell. Is using amazon cloudfront to stream the media going to make a big difference and what's a good technique for taking uploads in this situation? | The _right_ way is entirely dependent on what limitations you want to place on your users.
WordPress ships with a library called plupload. This is what powers the multi-file uploader in core, and it's available to create your own upload tools as well. The beneficial feature of plupload is the ability to chunk files on the client side before uploading them.
Essentially, plupload lets you split large files up on the client and upload much smaller files to the server. As a result, your server is more responsive (doesn't have to handle very long requests). On the downside, these features are difficult to implement in older browsers (read: Internet Explorer) and require stand-ins (read: Flash or Silverlight).
_Using_ plupload isn't a WordPress question, so if you go this route I encourage you to open new questions on SO. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "forms, uploads"
} |
Features Posts / Featured list WP Slider plugins?
For some reason I can't find any working / recent Wordpress plugins that have the featured content / list that are on the right of slider window.
**EG:** !enter image description here
Does anyone know where I can find any to use? | CodeCanyon is a great resource if you havent already visited it check it out. You will have to pay for most plugins but most are of a high standard.
Here are a few i found for you:
This one is very configurable and allows multiple layouts: <
This one is free and would be a piece of cake to make look like you example: <
Remember using some really simple CSS you can make alterations to sliders to suit your requirements.
Hope that helps | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "plugin recommendation"
} |
Having two different versions of the same post?
I'm currently working on a site that's targeted for beginners in a new language. Now I'm looking for something that can ease my work with having two different versions of the same post. One "easy to read" and one with more adept language.
In the front end there should be some sort of option that let the user tab to which ever version he or she would want to read. Would be good if the user could set a default value in the user profile aswell.
Anything ring a bell? I figure WPML would be worth a shot, but I haven't used it before, and I would like to try and find something else, since WPML also seems a little bit to advance for this purpose. | I think that having two separate posts for the easy/adept versions is going to be hard to manage consistently, especially if you end up with alot of content.
It would be easier to use custom fields to store the two sets of information within the one 'post', then use javascript to toggle between which one is visible on the frontend. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 4,
"tags": "multi language"
} |
Is there a way to lock certain pages from being edited by anyone other then the admin?
I have built a WordPress site and theme and have several pages that I do not want editors to edit. However, there are other pages that I want them to have access to to edit. Is there a plugin or code that will lock certain pages from being edited by anyone other than the admin? | Have a look at the Members Plugin by Justin Tadlock.
It has a " _content permissions_ " feature, that let's you restrict posts and pages by user role.
Alternatively, if you wanted to implement this yourself, you could write a shortcode that redirects the user conditionally. And place that on pages you want to restrict.
Since there is an excellent and well written plugin for this job however, this is one of the few occasions where I'd recommend using an existing plugin over coding it yourself. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 2,
"tags": "plugins, pages, admin"
} |
How to exclude/filter a tag from get_the_tag_list()
Does anyone know how to exclude/filter a tag from the HTML string generated by get_the_tag_list()?
<
Any help much appreciated. | function mytheme_filter_tags( $term_links ) {
$result = array();
$exclude_tags = array( 'some tag', 'another tag', 'third tag' );
foreach ( $term_links as $link ) {
foreach ( $exclude_tags as $tag ) {
if ( stripos( $link, $tag ) !== false ) continue 2;
}
$result[] = $link;
}
return $result;
}
add_filter( "term_links-post_tag", 'mytheme_filter_tags', 100, 1 );
// do loop stuff
echo get_the_tag_list('<p>Tags: ',', ','</p>');
// end loop stuff
remove_filter( "term_links-post_tag", 'mytheme_filter_tags', 100 ); | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 3,
"tags": "filters, tags, exclude"
} |
Float images in content
This is not a programming question. I have the problem to update the content in my WordPress blog. I'm very aware this problem can be solved by html modification. But my client doesn't know about html.So i need to give him relevant solution.
My Problem :-
I want to show my content as below screen. !enter image description here
But While i insert a post image content starts at the bottom of the image. This can be solved by html.But i need to know any other easy solution. !enter image description here
Thanks. | You need to setup CSS settings for `alignleft` class of your theme:
.alignleft, img.alignleft {
/* ... */
display: inline;
float: left;
/* ... */
}
And you need to add editor stylesheet where the same CSS will be presented. Create `editor-style.css` file in your theme, put content CSS settings there and call `add_editor_style();` from you functions.php file. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 1,
"tags": "editor, media, post content"
} |
HTML in PHP problem
I have the following code but I always get an error, it's the first time I've tried to merge HTML with PHP:
<?php
if(get_field('post_image'))
{
echo '<img src="'. get_field('post_image') .'" />';
}
else {
echo '<img src="<?php bloginfo('template_url'); ?>/images/images/default.jpg" />';
}
?>
Is there something wrong the blog info area? Is there an easier way to integrate these?
Thanks | You get the error because you try to call php inside php. Try to use this snippet and see what is different:
<?php
if(get_field('post_image'))
{
echo '<img src="'. get_field('post_image') .'" />';
}
else {
echo '<img src="' . get_bloginfo('template_url') . '/images/images/default.jpg" />';
}
?>
Also pay attention that `bloginfo` immediately prints value, when `get_bloginfo` returns it. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": -1,
"tags": "php, images, html, customization"
} |
Change the name of the 'Default Template'
I am working on a client's site and they need to select a Template whenever they are adding a new page; the "Default Template" is not a valid choice.
I would like to rename "Default Template" to something like "-- Select Template --".
Searching the WordPress codebase I found references to "Default Template" are hard-coded, in wp-admin/includes/meta-boxes.php (line 588) and wp-admin/includes/class-wp-posts-list-table.php (line 882). Does this mean there is currently no way to change this, without altering the core code (something I want to avoid)? | There is a filter for this since version 4.1; cf. <
You can now use:
add_filter('default_page_template_title', function() {
return __('My default template name', 'your_text_domain');
}); | stackexchange-wordpress | {
"answer_score": 9,
"question_score": 5,
"tags": "templates"
} |
grab neighboring content in a query
I'm grabbing a post based on a **querystring** parameter. How can I get the **neighboring** posts for a _previous_ and _next_ button?
This will get _tricky_ when you're on the first/last items.
Here is how I'm getting the target post:
$the_id;
if($_GET['the_id']) $the_id = $_GET['the_id'];
$arr = array('post_type' => 'my_cpt', 'showposts' => 1);
if($the_id >= 0) {
$arr['p'] = $the_id;
}
query_posts($arr);
*note that if there was now querystring param, I'm just loading from the _most recent_ post of that type. | use get_adjacent_post(). if nothing is returned for next/prev, get the first/last.
Edit- just noticed your custom post type, you'll also have to filter `get_previous_post_where` and `get_next_post_where` to pick up your cpt. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "query posts, next post link, previous post link"
} |
Merge two WordPress installations into one, and keep posts separated?
I have two Wordpress installations that I would like to make into one installation, but still keep the posts (and their meta-data) separated. Both installations currently share the same database.
I would like to be able to loop through both blogs, but each on their own page.
I have extracted both databases using the built in export function in WordPress and am now sitting with two .xml files containing the posts from each database.
Now I would like to import these posts into a new clean WordPress installation, BUT how can I keep the separated? I don't want them to get mixed up, because then I can't show them on their own page.. I am thinking about using a custom loop using WP_Query.
Thanks, I hope you understand what it is I want. | When you choose to import them into the new/merged website, you'll have the option to import the author, or to assign a new one to the imported posts. You could assign different authors to each import and use that to separate the content.
Do both use the same categories? If they don't it should be simple since they will retain the categories when imported. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "database, loop, merging"
} |
How To Hide The Visual And Html Editor Completely?
I have some clients that are going to be using wordpress for their sites. I created custom fields for them to input data in so they don't have to use the editor. How do I hide the page editor completely? I want it completely hidden so they don't accidentally muck things up. Thanks! | For posts:
add_action('init', 'my_custom_init');
function my_custom_init() {
remove_post_type_support( 'post', 'editor' );
}
See Codex. For custom post types that you register, you can specify what 'features' it supports when you register it it use the 'supports' arguments.
For custom post types that are not registered by you can use the above with 'post' replaced by the custom post type name. | stackexchange-wordpress | {
"answer_score": 7,
"question_score": 2,
"tags": "visual editor, html editor"
} |
Using Amazon Book Gallery Plugins in Wordpress
I am new to WordPress plugins. I have installed "Now Reading Reloaded" Plugin. My objective is to display bunch of books which i am reading or referring on a separate page : Books.
I have installed, Activated, Also registered the Amazon Web Services Access Key ID.
How to set the Plugin to the Books Page and make the list of books to display on that page? | Read the docs for the plugin. You need to use the template files (included with the plugin in the templates folder). You need to and modify the html and php to match your own theme's template files so you can use them in your own theme and have the pages look like your own theme's design. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "plugins, plugin recommendation, plugin wp e commerce"
} |
Edit Custom Database Tables in Wordpress
I have a site that uses custom database tables to manage info that is inserted by a process completely independent from Wordpress. The data from the table is used in the Wordpress site but it is not manageable through the Admin interface.
I want to make it manageable via the admin backend. What is the basic process for this? In my mind I need to create a link in the Admin sidebar to "Manage Custom Data" and that link opens up a page that permits basic CRUD management of the various rows in the table.
This would be effortlessly simply in vanilla code but I am not familiar with such custom aspects of modifying Wordpress so I am just looking for pointing in the right direction. Give me the big picture, in other words. | Some notes before: This is only _how I'd approach it_ \- I'm not going to step more into detail, because basically it's a list of plugins you'll have to code.
# Build a Back-End page
Use the function `add_menu_page` to add a page. Then build your management tables extending the `WP_List_Table` class:
class WPSE_48824_List_Table extends WP_List_Table
{
// do stuff
}
// Use it:
$list_table = new WPSE_48824_List_Table();
$list_table->display();
# Handling the DB
Basically you're going to have a lot of DB requests. Use the `$wpdb` object/Class.
Don't forget to `$wpdb->prepare()` your data before inserting it.
Also make use of `$wpdb->prefix` instead of hardcoding it.
# Bulk actions
Will run via Ajax. More can be read on Ajax for Plugins in Code or here on WPSE in the tag archive ajax. | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 3,
"tags": "custom field, customization, database"
} |
Deleting terms from the Wordpress wp terms table
what wp function do i use so that I can delete a term without worrying about the related tables such as wp term relationships and wp term taxonomy?
Also if a post has a relationship to the deleted term and it's the only relationship to any term does wp take care of the necessary and it's associated back to uncategorized ? What if there is no uncategorized term neither? | Use this: `wp_delete_term`
Edit: Did a little dig around. With custom taxonomies, if you delete the term, the posts will not be assigned a new one. With 'category', whichever you set as the default from 'Writing Settings' will be assigned to the post. Besides, if you want to set the default category from code, use `update_option('default_category', '<category name>')`. There's a third argument with `wp_delete_term`, using which you can force a default category, but I really couldn't find how to use this argument. (Ref: ../wp-includes/taxonomy.php, l. no. 1681) | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "wp query, wp insert post, terms"
} |
How can I execute shortcode outside the loop?
I'm using Contact Form 7 and can display the form by putting the following in the content text field `[contact-form-7 id="453" title="Contact form 1"]`.
Now I need to display the form outside the loop.
How can I execute a short code from within my template code?
**Update**
I found some suggestions to execute shortcode outside the loop:
<?php echo do_shortcode('[contact-form-7 id="453" title="Contact form 1"]') ?>
This solution works fine :) | do_shortcode should do the trick. I don't think you need the 'echo' before it though, I have never done so myself and never had any problems. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "shortcode"
} |
Multiple domains with different child themes on one installation?
Is it possible to have multiple domains (each with unique child theme) on one installation?
I'm aware of Wordpress's new feature called "Network", which allows you to have one installation for multiple sites.
Ideally each site will have it's own child theme, or something similar. | Use the plugin WordPress MU Domain Mapping. Read the installation instructions _very_ carefully. There is also an ebook WordPress Multisite 101 where you can read more (like migration from single site installation etc.).
You can activate themes per single site as usual. Or set the constant `WP_DEFAULT_THEME` in your `wp-config.php` depending on the host name:
switch ( $_SERVER['HTTP_HOST'] )
{
case 'example.com':
define( 'WP_DEFAULT_THEME', 'blue-child' );
break;
case 'example.net':
define( 'WP_DEFAULT_THEME', 'red-child' );
break;
default:
define( 'WP_DEFAULT_THEME', 'parent-theme-slug' );
} | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 2,
"tags": "multisite, domain mapping"
} |
Get Featured Image via direct sql query
I know you can use the wordpress methods for getting a featured image, however with this particular project I need to get the featured image via mysql query. Can anyone point me in the right direction. Thank you.
This is what I have so far but my query is not doing the trick. I have the $post->id stored as a variable called $da_id
$Featured_image = $wpdb->get_results("
SELECT *
FROM net_5_postmeta
INNER JOIN net_5_posts ON net_5_postmeta.post_id=net_5_posts.ID
WHERE post_parent = $da_id
AND meta_key = '_wp_attached_file'
ORDER BY post_date
DESC LIMIT 15",'ARRAY_A'); | $Featured_image = $wpdb->get_results("
SELECT p.*
FROM net_5_postmeta AS pm
INNER JOIN net_5_posts AS p ON pm.meta_value=p.ID
WHERE pm.post_id = $da_id
AND pm.meta_key = '_thumbnail_id'
ORDER BY p.post_date DESC
LIMIT 15
",'ARRAY_A'); | stackexchange-wordpress | {
"answer_score": 5,
"question_score": 8,
"tags": "post thumbnails, query, mysql"
} |
How to properly turn off REVISIONS and AUTOSAVE for whole site and optionally for a custom post type only
Is there a hook/function combination that can be added to my theme's `functions.php` to properly disable REVISIONS and AUTOSAVE for the entire wordpress installation? What about if just for a certain custom post type? Searching online gives various hacks from deregistering scripts to tampering with core files. What's the acceptable/correct way to do this? | This should be placed in your `wp-config.php` (and no where else):
define( 'AUTOSAVE_INTERVAL', 60*60*60*24*365 ); // Set autosave interval to 1x per year
define( 'EMPTY_TRASH_DAYS', 0 ); // Empty trash now: Zero days
define( 'WP_POST_REVISIONS', false ); // Do not save andy revisions | stackexchange-wordpress | {
"answer_score": 15,
"question_score": 12,
"tags": "custom post types, revisions, autosave"
} |
List direct children of page
I am currently using the following function to list the children of a page, however the function recursively finds children of the children and I only want to list the direct children of `$post->post_parent`.
wp_list_pages(array('child_of' => $post->post_parent,'exclude' => $post->ID))
Does anyone know how to do this? | Try this:
wp_list_pages(array('child_of' => $post->post_parent,'exclude' => $post->ID, 'depth' => 1))
Read the codex for more details. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "posts, php, functions, get children"
} |
Is there a way to hook into the update-core page for custom messages?
We have some sites where we note a few things that need to be checked or done either before or immediately after a core, theme or plugin upgrade. While I keep a list of these things, sometimes users themselves do the upgrade and mess everything up.
I was hoping to be able to add a message to the upgrade screen to remind myself of the checklist of to do's before/after upgrade and also to warn users to contact me etc.
I'm thinking if there is a hook to let me add this customized message that'd be great. If not any suggestions how to approach this? Thanks! | There is an action, `'core_upgrade_preamble'`, which can be added to output anything you would like at the bottom of the upgrade-core page. For example, try:
add_action('core_upgrade_preamble', 'add_custom_upgrade_core_message');
function add_custom_upgrade_core_message(){
echo "<p>HI THERE</p>";
}
That should work to meet your needs. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 1,
"tags": "admin, updates, notices"
} |
How to place my g+ or fb plugin at the bottom of post or page?
I recently installed the google+ and facebook widget plugins to my pages and I do not like it's current position. I'm not sure where to begin looking.. Thanks. | It depends on the plugin, but you could edit your post template and either use a template tag (if one exists), a shortcode (if one exists), or call the widget directly. Either way, you'll have to edit the template (unless you want to register a new sidebar). | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "widgets"
} |
$post object is null
I am trying to use the `$post` object from functions.php in my theme however if I attempt to `var_dump($post)` it returns `NULL`.
Here is my code:
function breadcrumb_navigation() {
var_dump($post);
$page = $post;
$parents = array();
while ($page->post_parent){
array_push($parents, $page);
$page = $page->post_parent;
}
if (sizeof($parents) > 0) {
array_reverse($parents);
foreach($parents as $parent) {
echo '<li><a href="'.get_permalink($parent->ID).'">'.$parent->post_title.'</a><ul class="child">', wp_list_pages(array('child_of' => $post->post_parent,'exclude' => $post->ID)), '</ul></li>';
}
}
}
Can anyone tell why this would be happening? | Call in `global $post;` at the top of the function. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 2,
"tags": "posts, php, functions, pages"
} |
Why might a comment turn red on approval?
Weird question here, but I'm hoping somebody is familiar with the issue.
When an admin clicked on the "approve" link under a comment on the comment moderation screen, the entire comment row turned red. The comment did publish--but the "approve" link was still appearing in the list of actions links (when it should have changed to "unapprove"). After refreshing the comments moderation page, everything went back to normal.
Not exactly an important issue. But I need to be able to explain why it happened, and I can't reproduce it (though I believe it happened--she sent me a screenshot). Any thoughts? Anybody seen this before? Is this maybe a common UI convention in WP when AJAX calls fail? | Got it figured, so I'm closing this question out.
Here was the problem: on comment approval, I had some custom stuff hooked, and this custom stuff was throwing an error. This error was being included as part of the comment approval's AJAX response.
It turs out that on listings pages in the admin, if WordPress encounters an unknown AJAX error , it deliberately turns the offending row red. You can see the color being explicitly set in wp-includes/js/wp-lists.dev.js in the function "ajaxDim". | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "comments"
} |
How to declare/provide file path in JQuery which is emeeded in the Wordpress theme
How to give the source location path in the jquery code, where my file is in **cah-new/wp-content/themes/theme_name/includes/func.php** and i have to give that path in the jquery code
$.get(\"func.php\", {
kindly help me, thanks in advance | $.get('<?php echo get_bloginfo('template_url')?>/includes/func.php', { | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "jquery, paths"
} |
how to change # of tag posts on /tag page?
I have my blog page limited to 5 posts on the main page, which I'm happy with. However, I want my tag pages to list much more, maybe 15 or so. How do I most easily make this change? There's no option on the reading page.
thx! | I would put this in functions.php:
function main_query_mods( $query ) {
// check to play with other queries
if(!$query->is_main_query()) {
return;
}
if(is_tag()) {
$query->set('posts_per_page',15);
}
}
add_action( 'pre_get_posts', 'main_query_mods' ); | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 0,
"tags": "tags"
} |
Using wp_dropdown_users and selected() function?
I have a custom meta box with a dropdown displaying all the WP users via wp_dropdown_users. It saves which WP user is chosen with the post, so that all works.
However, is there a way to make it show the selected user in the dropdown when going back to edit, rather than the first in the list? I've used the selected() function for another dropdown but I've created that dynamically. I've tried to implement selected() with wp_dropdown_users, but it hasn't worked so I'm not sure if it's even possible?
Thanks! | You need to set `selected` argument for the `wp_dropdown_users` function. Do it like this:
wp_dropdown_users( array(
// ...
'selected' => $user_id,
// ...
) );
Read documentation for wp_dropdown_users function | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "dropdown"
} |
add_theme_support( 'custom-header' ) does not add option menu in dashboard
I'm writing a new theme from scratch, based off the Toolbox theme. My installation of WP is straight out of the box. I added add_theme_support('custom-header'); to my functions.php file, but the "header" options screen does not appear in the dashboard. I can see it if I visit the site, in the toolbar at the top, but not in the dashboard. Am I missing something? | I was told that `add_theme_support('custom-header');` is not supposed to work as I expected yet. See the full answer I received here. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "theme development, themes, add theme support, custom header"
} |
How to get permalink using get_blog_post function in a multisite?
I'm using code like this
$post = get_blog_post( $blog_id, $data );
echo __('Post on') . ' "<a href="'.$post->guid.'">' . $post->post_title . '</a>"';
But the href link looks like this `mysubdomain.example.com/?p=345` instead of permalink.
Can anyone tell me how to get permalink ?
Thanks | Ok i found the answer.
$post = get_blog_post( $blog_id, $data );
$link = get_blog_permalink( $blog_id, $data );
echo __('Post on') . ' "<a href="'.$link.'">' . $post->post_title . '</a>"';
I hope it will be useful for others :) | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "multisite, permalinks"
} |
modify plugin to support RTL
I've developed a plugin and now I want to make it RTL compatible. Does anybody know how to determine is RTL enabled in admin panel or not? Or maybe somebody knows any CSS tips for RTL support? | I think you're looking for the function `is_rtl()`.
Have a look in de codex: < | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 0,
"tags": "plugins, plugin development"
} |
How to get the first tag of a post as a hyperlink?
This WordPress Codex document clearly shows how to get the name of the first tag of a post:
<?php
$posttags = get_the_tags();
$count=0;
if ($posttags) {
foreach($posttags as $tag) {
$count++;
if (1 == $count) {
echo $tag->name . ' ';
}
}
}
?>
How do I modify the aforementioned code, so that a hyperlink of the tag is shown, instead of just the name? | Instead of
echo $tag->name . ' ';
use
echo get_tag_link( $tag->term_id );
See the Codex on `get_tag_link()` and `term_id`.
And encapsulate the code in a function. Put this into your `functions.php`:
function wpse_49056_first_post_tag_link()
{
if ( $posttags = get_the_tags() )
{
$tag = current( $posttags );
printf(
'<a href="%1$s" itemprop="url"><span itemprop="title">%2$s</span></a>',
get_tag_link( $tag->term_id ),
esc_html( $tag->name )
);
}
}
In your `single.php` you just call the function where you need the link:
<?php wpse_49056_first_post_tag_link(); ?> | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 0,
"tags": "tags"
} |
Rewrite /category/cars into /topics/cars
I know there are plenty of question and posts about this out there, however I couldn't find a solution or existing thread to my specific question.
If I list my categories and click on "cars" the url looks like this
`url/category/cars`
Is it simply possible to use some function in functions.php to change the word `category` into e.g. `topics`
`url/topics/cars`
Any ideas on that? Thank you in advance! | If you go to Settings->Permalinks and change `Category Base` to topics, you won't even have to write any code to make the change, as wordpress includes this functionality by default. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 0,
"tags": "url rewriting, urls, rewrite rules"
} |
What are the benefits of using wp_enqueue_script?
Is there any real benefit to using wp_enqueue_script on small self-managed sites? For instance, Modernizr, why enqueue it through a function rather than call it directly inside the document head?
I can see the benefit on large sites, where you may move around directories or have multiple people mucking around in the files, or in a publicly available theme with numerous unknowns, but what's the benefit on a small site like a personal blog that never - or rarely - changes and has a single user? It just seems like extra lines of code in that case. | 1. **Are you using a Theme that you control?**
If not, then every time the Theme updates, you'll lose your modifications to the header. Or else, you'll have to fork the Theme, or maintain/backport your changes every time the Theme updates.
2. **Do you only use Plugins under your control?**
If not, then you'll have to check for script conflicts every time you activate or update a Plugin that uses a script.
3. **Are you using a core-bundled script?**
If so, then you'll have to check for core script conflicts every time you update core, as well as every time you update a Plugin that enqueues a core-bundled script.
4. **Do you use a caching Plugin?**
If so, then you lose some or all of the benefits of script concatenation/minimizing/caching, since your script is hard-coded in the document head rather than enqueued. | stackexchange-wordpress | {
"answer_score": 11,
"question_score": 9,
"tags": "javascript, wp enqueue script, scripts"
} |
Combining multiple conditional statements
I need a 3 part conditional statement with all negatives but I can't get it to work. I need to say that the post isnt in category 'videos' or its child categories and isn't from the author with the id of 3. This is what I had but obviously doesn't do the trick.
if (!in_category('videos') || !post_is_in_descendant_category(9) && !is_author('3')) | I like to split this kind of thing to more than one conditional, as it makes it easier for me to read.
if( !( in_category( 'videos' ) || post_is_in_descendant_category( 9 ) ) ) {
if( get_the_author_meta( 'ID' ) != 3 ) {
}
}
Given, it's a bit more code, but that's the way it reads best to my eyes. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": -1,
"tags": "posts, conditional tags"
} |
debugging wordpress
I noticed that when I'm working on a php page that loads wp programmatically, some of my errors are not fired. For example, a variables that has not initialized previously creates a warning when I have the E_ALL on top, but not when I load wp after that.
Any comments?
how do I put wordpress in a mode so that anything wrong anywhere is reported. | if you set `WP_DEBUG` to `true` in `wp-config.php` it should output all your errors. Alternatively, you can use something like Debug Bar or BlackBox to display the errors. How much you need should determine your solution. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "debug"
} |
Can Permalink structure of %postname%/%post_id% improve performance
Since the post_id is unique and no full text search is needed.
So is the structure **%postname%/%post_id%** really improve performance? | I hate to answer this with a link, But with WordPress 3.3, how it searches for permalinks have been greatly improved so you can almost put anything into the permalinks and it will be fast.
< | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "posts, permalinks, urls, performance"
} |
Restrict WordPress to Private
I want to set up a private WordPress site, with only 2 users, all I need is a simple private site functionality, with visitors unable to see anything when trying to login, only being redirected to the login page. RSS should also be blocked.
I have found one plugin which does this, but it doesn't seem to be maintained, any others which do the same thing and are maintained?
< | Use this :
<
> A very simple way to quickly password protect your WordPress site with a single password. Integrates seamlessly into your WordPress privacy settings.
>
> **How can I change the WordPress logo to a different image?**
>
> Install and configure the Login Logo plugin by Mark Jaquith. This will change the logo on your password entry page AND also your admin login page.
!enter image description here | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "private"
} |
Where do i create my own function in wp-admin
i want to create my own function in wp-admin same like do in wp-content->functions.php, but i don't know where is the function file in wp-admin folder.
anybody know where is the function file in wp-admin folder? | There is no function file in "wp-admin" folder, you do not need to edit that folder.
Wordpress has Plugin api to do that, <
Create a plugin and write function in your plugin file. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 0,
"tags": "functions, wp admin"
} |
Remove HTML editor and visual/HTML tabs from TinyMCE
Is it possible to remove the `Visual` \ `HTML` tabs from `wp_editor` and display only the TinyMCE editor?
Basically, right now, I'm using `wp_editor` to display the smallest possible TinyMCE editor I can - only one button is needed, italics.
!Current TinyMCE instnace
What I'd like to do is make that smaller by removing the `Visual` \ `HTML` tabs. Our authors won't ever need the HTML editor and the custom buttons I'm creating will only be accessible from the visual editor.
**NOTE:** For reasons found here, I can't use the `teeny` argument of `wp_editor`.
Thanks in advance, | Just set 'quicktags' parameter of the settings array to false.
wp_editor('', 'some-id', array('quicktags' => false) ); | stackexchange-wordpress | {
"answer_score": 21,
"question_score": 12,
"tags": "tinymce, wp editor"
} |
Need idea: custom post type and custom meta
I'm working for a WordPress Plugin. The plugins is for library management, for my university. I created custom post types with taxonomies for keeping books information stored. Now I want to create another post type which will keep records for books and and users. For instance, I'll create new post type called "Issue". There should have three fields. One would be title. Another two will be dropdown, one will show all book (I've already created custom post type called books, I want to use those here, automatically) lists as dropdown. Another dropdown field will show list of students (for this I've created a new user role called student, I want to use those user who are registered as student).
So my questions are
1. How can I show all users (selected role) as dropdown in custom meta box and
2. How can I show all books (Custom post type I created) as dropdown in custom meta box
How can these be done? I can code, need instruction ;) | * To get the users who have the role called student, use the `WP_User_Query` object
* For storing the fields, use post meta just as you would on normal posts, remember to declare that your custom post type supports custom fields when being registered
* For your dropdown/etc you will need to register metaboxes
More info on `WP_User_Query`.
For how to add metaboxes see the Codex entry and examples for this function. | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 2,
"tags": "custom post types"
} |
integrating external php library into wordpress- the right way
If I were to load a custom library into wordpress, what would be the best place to add it?
Since there are a bunch of global vars defined at the top of the library, I would not want that to be done thru a hook where I'm forced to use a wrapper function whereby my library globals will be treated as local to that function.
My library starts with
ob_start() // I'm not sure how this would effect WP. So I'm not too big on this.
session_start(); // I do need this though.
This should make any wordpress page to be able to use PHP sessions, right? ( I'm assuming wordpress no internal code that kills/rejects session usage. )
If I put my library into a page such as mylibrary.php, how do I make sure that it gets included into wordpress ( all pages, cats, template files across themes ) and it will remain included even if I were to switch themes or deploy wordpress updates? | You might want to look into creating a MU (Must Use) plugin, see Wordpress Codex. Within this file, you can include your library (using `require`) or you could just tweak your library file a bit and use it directly as the MU plugin. The `session_start()` and `ob_start()` functions worked for me with ever-so-brief testing, but your mileage may vary so test test test :) | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 2,
"tags": "php, include, wp config, framework, session"
} |
How to consolidate multiple static page templates into one dynamic one?
I have a group of themes that a client needs consolidated into one. Everything is fairly straight forward, except each theme has theme-specific page templates. Instead of pooling all the template files together in the new master theme, how can I reduce them down to one dynamic template that displays differently depending on a chosen theme option?
When searching myself I came across the template_include filter, which looks like it could be used to override the template that is used, but I'm not sure this is the right solution or how it would be implemented in this case.
Another idea I have would be to just use conditional includes inside the "master" template.
Any suggestions would be much appreciated. | Personally, I build everything within index.php of each template. I then do conditional checks.
Example:
if(is_front_page()){
// Home page layout
} elseif(is_page()){
// General page layout
if(is_page('contact')){
// Page layout specific to the contact page
} elseif(is_page('about')){
// Page layout specific to the about page
}
}
Read more on conditional tags. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 4,
"tags": "page template"
} |
Show different theme for admin?
I'd like to test some theme changes on my live site, but I obviously don't want regular users seeing any errors that may arise from it. I'd like to just duplicate my theme folder and if I'm logged in as admin, then that theme is shown to me, otherwise, the old theme is shown to my users.
Is there a plugin to do this? | I just wrote this quick plugin and it seems to work. Let me know if there is a better way.
<?php
/*
Plugin Name: Theme Switch if Admin
Description: Display different theme to user if logged in as admin
Author: Kyle Barber
*/
add_filter('template', 'change_theme');
add_filter('option_template', 'change_theme');
add_filter('option_stylesheet', 'change_theme');
function change_theme($theme) {
if ( current_user_can('manage_options') ) {
$theme = 'twentyeleven';
}
return $theme;
} | stackexchange-wordpress | {
"answer_score": 14,
"question_score": 9,
"tags": "themes, testing"
} |
How long to keep old domain for 301 redirects after moving WordPress?
I'm looking into moving my WordPress blog from an old domain to another domain that I own. The old domain is getting expensive at $25/year and I have to renew in a month. I had the old domain for 15 years but it no longer serves it's purpose as a standalone blog.
I have several options for handling this:
1. Leave it as is and keep paying the renewal registration.
2. I can do the move right now and let the registration expire next month.
3. Make the move and renew for another year before letting the registration expire.
How long do I need to keep the old domain up for the 301 redirects to be effective before I let the registration expire? | I found my answer on Google's Moving Your Site page.
> To prevent confusion, it's best to retain control of your old site domain for at least 180 days.
Due to circumstances beyond my control, my WordPress installation broke down. I did a fresh install at the other domain, imported my WordPress database and files, and set up the 301 redirect. Everything is working smoothly. I'll be keeping the old domain for another year before letting it expire.
Thanks for the other answers! | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "domain, redirect"
} |
Strip the + symbol from the_search_query
When using the_search_query to display search result on my site, the spaces between words are displayed with a **+** symbol.
So if a visitor searches for "wordpress plugins" the_search_query output in search.php returns
wordpress+plugins
How can I remove the + symbol, and/or replace it with non-break space entity, like so .....
wordpress plugins
or
wordpress plugins
I tried this approach but it is not working .....
<?php
$string = the_search_query();
$res = preg_replace("/[^a-zA-Z]/", "", $string);
echo $res;
?> | Personally, when I do things like this I use `str_replace()` [Link]
Using your above example it would be implemented like so:
<?php
$string = the_search_query();
$res = str_replace("+", " ", $string);
echo $res;
?>
That will replace any `+` with a space.
Or if you want the ` ` use this:
<?php
$string = the_search_query();
$res = str_replace("+", " ", $string);
echo $res;
?>
On a minor note, this question is not really WP related and may get bounced to StackOverflow or closed by a mod. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "search"
} |
Is wordpress 3.3.1 compatible with PHP Version 5.2.17?
Exactly what it says on the tin, I am having a few problems with my site after a server upgrade and some of it has started to trip out.
A lot of my code has also stopped working, despite it doing nothing fancy, mostly just loops and ifs just wondering if because a lot of it is dependant on WP functions. | Yes, it is. From the requirements page:
> * PHP version 5.2.4 or greater
> * MySQL version 5.0 or greater
>
You don't need an update, try the various debug tools to see what goes wrong. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "compatibility"
} |
How can I post Facebook fan page status updates to my WordPress blog?
Is it possible to get an RSS feed of Facebook status updates from a Page rather than a Profile? I want to use the feed in WP's RSS feed widget.
It's easy to pull statuses from a profile page. I did this using an RSS feed widget. I tried doing the same thing for a fan page, but Facebook forces me to switch contexts (from viewing as the a page to viewing as myself), after which I'm redirected to my own status feed.
There is an RSS for notifications, but I want it for statuses, not notifications. | Pretty sure the Facebook fan page RSS feed URL is like this:
The fan page ID is the string of numbers at the end of the URL when viewing the page, for example, Jon Stewart's fan page id is 193859733506:
So you can do your normal RSS feed solution which takes entries and uses them in your Wordpress site, and use that URL format above for the fan page you are after. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 1,
"tags": "rss, facebook"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.