New answers tagged functions
0
Either go and extend the class, or copy, paste and rename it (not recommended).
class Child_Theme_Widget extends Parent_Theme_Widget
{
// just re-define/override the parent theme widgets methods (functions) here
}
2
In your code example you have:
wp_schedule_event( time(), 'hourly', 'symbiocards_hourly_event');
but there is no symbiocards_hourly_event hook defined.
If you are using it in the functions.php file in your current theme directory, then please try this snippet instead:
add_action( 'wp', 'symbiocards_activation' );
add_action( 'symbiocards_hourly_event', ...
0
I have never tried to do what you are trying to do, so no promises, but there is an action hook called upgrader_process_complete in the upgrade method of the Theme_Upgrader class, and it look like it would do what you want. The action is called like:
do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'theme' ), ...
1
your ajax url is wrong i think. ajax link should be admin_url( 'admin-ajax.php' ). That means
wp_localize_script('history_script', 'myAjax', array('ajaxurl' => get_template_directory_uri().'/functions.php'));
will be this
wp_localize_script('history_script', 'myAjax', array('ajaxurl' => admin_url( 'admin-ajax.php' ));
0
if ( wpse_99666_check_user_roles( array( 'customrole', 'author' ) ) )
_e( "You've got access dude!", 'appthemes' );
else
_e( 'Sorry man, no luck.', 'appthemes' );
/**
* Checks if a particular user has one or more roles.
*
* Returns true on first matching role. Returns false if no roles match.
*
* @uses get_userdata()
* @uses ...
1
This is a known issue. It is caused by a bug in PHP 5.2 and is fixed in PHP 5.3.
You need to manually call the destructor method before unsetting the $feed and $item variables.
source
0
Themes do not have an equivalent of register_activation_hook() like plugins.
You may also run into issues during a review if you're hoping to be hosted on the repo. I'm not sure how creating categories classifies exactly, but doing things like creating post types is explicitly disallowed.
That said, you can use wp_create_category() in your functions.php ...
0
This is completely untested but I think the concept is good, and good idea too though I'd have an angry mob with pitchforks to face.
Set a marker for your post when the post is previewed. You can save
it in either $wpdb->options or $wpdb->postmeta. I haven't
quite decided which would be better, and it probably depends on
details of the ...
0
So in your theme setting page do something like this:
if( isset( $_REQUEST['resetl_all'] ) ){
call_reset_function(); // or newtheme_get_theme_mods function (I guess)
}
1
You can only return one chunk of data from a function. That is a PHP enforced rule. If you need to return multiple pieces of data you need to return an array or an object.
With filters, though, you can't just decide what to return. You have to return what the filter is meant to return. For example, the_content callbacks need to return a string. Returning a ...
0
To add to @Pat's answer above. Try to add this to your CSS.
img {
width:100%;
}
Sometimes thats all it takes
0
If $content_width is the problem, you could set it to something different if you're viewing a single HQ post.
function wpse99587_single_hq_post() {
global $post;
if( is_single() && in_category( 'HQ', $post->ID ) ){
global $content_width;
$content_width = 900;
}
}
add_action( 'wp', 'wpse99587_single_hq_post' );
// I ...
0
You can just remove or comment out the line:
wp_enqueue_script('inkthemes-confu-ui', get_template_directory_uri() . "/js/cufon-yui.js", array('jquery'));
Update:
You would also need to remove or comment out:
wp_enqueue_script('inkthemes-quicksand-confu', get_template_directory_uri() . '/js/mank-sans.cufonfonts.js', array('jquery'));
Which is the font ...
1
You can remove scripts with wp_dequeue_script():
function wpse99450_remove_cufon() {
wp_dequeue_script( 'inktheme-confu-ui' );
// inktheme-confu-ui is the script's handle, according to your posted code
}
add_action( 'wp_enqueue_scripts', 'wpse99450_remove_cufon', 20 );
// set priority to '20' so it will run later than the default
But be careful -- ...
1
This is not an exact answer, but I think there are enough elements to build the desired output.
I sort the menu manipulating the global $menu, not really best practice, but for now it works.
The result of this example is moving Links Manager, Comments and Media Library to the end of the first block. The effect is: first all Post Types then these items.
We ...
1
If you want just a read more link instead, replace <?php the_excerpt(); ?> with:
<a href="<?php the_permalink() ?>">Read more</a>
This will create the same link as the image, just with text.
1
You just need to replace this line:
<?php the_excerpt(); ?>
With this line:
<?php the_content(); ?>
That should insert your post's content instead of an excerpt.
1
You are dealing with a class method not a function. Look down at the bottom of that code and you will see...
$crfp = new CommentRatingFieldPlugin(); // Invoke class
$crfp is the class instance. You will need something like...
global $crfp;
if (isset($crfp) && method_exists($crfp,'DisplayAverageRating')) {
$crfp->DisplayAverageRating('');
}
...
1
Looking at the code it's not a function, it's a method of CommentRatingFieldPlugin class, instance of which is being assigned to $crfp global variable.
So your should be something like:
global $crfp;
$crfp->DisplayAverageRating();
0
You're getting this because you're running PHP 5.2 on your server. The plugin requires PHP 5.3. If it did not do this check, you would get an error when it tried to use a PHP 5.3 feature.
I won't recommend a plugin as that would be offtopic and result in the question being closed ( hint: edit that out of your question ).
The fix, is to upgrade to PHP 5.3, ...
0
You could use the wp_dropdown_categories() function and pass post_tag as taxonomy parameter.
<?php wp_dropdown_categories( array( 'taxonomy' => 'post_tag' ) ); ?>
0
It turns out the free Relevanssi plugin does this rather well. I was afraid it would only search posts and not custom post types, but it does it all... and rather well! It only requires a simple filter added to your theme's functions.php file to get it to omit the body content:
// search titles only (relevanssi plugin)
add_filter('relevanssi_index_content', ...
2
I put the script in a external file
// Excerpt word count
function excerpt_count_js(){
wp_enqueue_script( 'excerpt-word-count', plugins_url( 'excerpt_word_count.js', __FILE__ ), array( 'jquery' ), false, true );
}
And modified the script a bit
jQuery(document).ready(
function($){
$("#postexcerpt .handlediv")
.after("<div ...
1
Consider this snippet here to accomplish your task. If you add it to your functions.php file, the Open Graph tags will be populated automatically as part of the wp_head action.
2
First line of the codex for get_content:
Displays the contents of the current post. This template tag must be
within The_Loop.
Also, this line:
<meta property="og:description" content="<?php string_limit_words(the_content(), 15);" ?> />
would need to get_the_content(), as the_content() will output, and you need to return.
<meta ...
6
Our journey starts here with the WP_Customize_Background_Image_Control class, which is a WP_Customize_Image_Control.
I'd imagine offering these built-in backgrounds in a new tab alongside the existing Upload New and Uploaded tabs. There are at least two ways of achieving the following: either creating your own modified class based off of the ...
0
Ugh. Fixed.
You have to show the 2nd category box in screen options, I could only see the default post categories. I'm glad I spent 40 mins trying new bits of code for that.
Thanks
6
There are a couple of problems with your code:
You have to close the PHP context, if you want to output plain HTML: function foo(){ ?><strong><?php }
Don’t repeat yourself. Always store repeating values in variables or functions. Writing <a href more than once is a bug.
Do not use get_the_title() in attributes. Use the_title_attribute( array ...
0
First of all, you never closed your php tags.
Second of all, do not call functions each time for each social icon. Save values in the variables instead to speed up the process.
It would go something like this:
<?php function my_social_buttons() {
$title = esc_attr( get_the_title() );
$permalink = esc_attr( get_the_permalink() );
$directory ...
2
You cannot do that with pure PHP, because the fields are fetched from existing fields, and there is no hook. But you can use JavaScript, check if the post type supports custom fields and the field does not exist already – and insert it:
<?php # -*- coding: utf-8 -*-
/* Plugin Name: Extend custom fields */
add_action( 'admin_footer-post-new.php', ...
1
Manipulating HTML with regular expressions is not a good idea. I suggest you use DOMDocument:
// input
$html = apply_filters('the_content', get_the_content());
$dom = new \DomDocument();
$dom->loadHtml($html);
$blockquotes = $dom->getElementsByTagName('blockquote');
foreach($blockquotes as $blockquote){
foreach($blockquote->childNodes as $e){
...
0
Maybe you can use a simple preg_replace, but you have to remove spaces around P in this example
$result = preg_replace('< p [^>]>(?:\s+|(?: )+|(?:)+)', '', $content);
If you will not use any tags inside blockquote, maube you can use strip_tags($content); to remove all html tags
0
I use the plugin Simple Image Sizes. If you do not want to use a plugin you have to use the function add_image_size
3
I'd use a must use plugin. The code will apply across the network while your clients won't have access to it so they won't be able to disable or modify it.
To proceed you just have to put your code in one single file and put it in /wp-content/mu-plugins/
Hope this will help :)
6
Use a plugin for that. Hook into after_setup_theme and check if the current theme is the correct child theme:
add_action( 'after_setup_theme', 'common_child_theme_functions' );
function common_child_theme_functions()
{
if ( 'Twenty Twelve' !== wp_get_theme()->parent() )
return;
// do your work
}
wp_get_theme() returns a WP_Theme ...
1
You can include just about any file you want from any of the child themes, but there is little known feature to WordPress called Must Use plugins. I think I would lean towards that.
Create a directory called mu-plugins in wp-content
Create a file in that directory and add your functions to it.
Unlike ordinary plugins, must-use plugins do not show up in ...
6
Well, I'd say that you need a custom plugin. All the rationale is in this Q&A:
Where to put my code: plugin or functions.php?
Also related:
Where do I put the code snippets I found here or somewhere else on the web?
Create a Functionality Plugin Instead of Using Functions.php
And answering to the Question, create the following file ...
1
The default widgets do not offer any hooks for that. You have to replace the default widget and add your field to the new class.
The other option would be using JavaScript to insert the field, and a filter for 'update_option_widget_' . $widget->id_base to save the value.
I think the separate class is the cleaner approach.
1
';)' => 'icon_wink.gif', is in line 2477 in the current version, you should never just change or delete core files, unless you know how to run a private branch of WordPress.
Line 2925 is the second trigger_error() in this function:
function _deprecated_argument( $function, $version, $message = null ) {
do_action( 'deprecated_argument_run', ...
-2
Please Remove all $wpsmiliestrans: ;) => ---- from your function file. and use this plugin for smiles .
Smilie Replace Plugin
2
By inspecting the file /wp-admin/nav-menus.php we can see that these meta-boxes:
are rendered with:
<?php do_meta_boxes( 'nav-menus', 'side', null ); ?>
The file /wp-admin/includes/nav-menu.php contains the corresponding add_meta_box() calls and from that we can construct the relevant removal code:
function custom_remove() {
...
0
<?php
add_action('iphorm_post_process_1', 'mytheme_create_wp_post', 10, 1);
function mytheme_create_wp_post( $form ) {
$title = $form->getValue('iphorm_1_1');
$content .= 'Δώρα διαγωνισμού: ' . $form->getValueHtml('iphorm_1_30') . '<br />';
$content .= 'Διοργανωτής διαγωνισμού: ' . $form->getValueHtml('iphorm_1_36') . '<br/>';
...
1
In addition to @vancoder's answer, you are also missing a comma in the $post array.
$post = array(
'post_title' => $title,
'post_content' => $content, // <-- that comma is missing in your code
'post_status' => 'draft'
);
That causes the T_CONSTANT_ENCAPSED_STRING error when the script hits the following line.
This problem is just ...
1
You need to remove the space between <? and php at the very start of your file.
Incorrect:
<? php
add_action('iphorm_post_process_1', 'mytheme_create_wp_post', 10, 1);
function mytheme_create_wp_post($form)
{
Correct:
<?php
add_action('iphorm_post_process_1', 'mytheme_create_wp_post', 10, 1);
function mytheme_create_wp_post($form)
{
This ...
1
Modify the searchform.php, or create one in a child theme (recommended), and you should be able to modify the form all you want.
This is the file that get_search_form looks for and is the file used by the default search widget, though it is not listed in the Template Hierarchy.
Reference:
http://codex.wordpress.org/Function_Reference/get_search_form
0
You can filter 'wp_nav_menu_args', set an invalid theme_location and the magic function __return_false as fallback:
add_filter( 'wp_nav_menu_args', 'override_parent_args' );
function override_parent_args( $args )
{
if ( 'header-menu' === $args['theme_location'] )
{
$args['fallback_cb'] = '__return_false';
$args['theme_location'] ...
1
Got it to work by using ACF's custom functions instead of wp's meta functions.
Final working result:
//Set post thumbnail based on various conditions
if (get_post_meta($post_id, 'featured_image', true)) {
$attachment_id = get_post_meta($post_id, 'featured_image', true);
} elseif (get_post_meta($post_id, 'upload_single_image', ...
2
You have to set the $single paramter of get_post_meta to false (or don't set it) to get an array.
Here is a sped-up version:
if ($attachment_id = get_post_meta($post_id, 'featured_image', true)) :
elseif ($attachment_id = get_post_meta($post_id, 'upload_single_image', true)) :
elseif ($attachment_id = get_post_meta($post_id, 'create_gallery', ...
0
Need a functions that adds (adm)/(mod) if current user is admin/moderator right after their username
You can ask for roles with current_user_can() too:
current_user_can( 'administrator' )
or
current_user_can( 'editor' )
There is no built-in role moderator.
0
I came across this thread trying to solve the same problem - this is what I've come up with. I don't know how well this performs, since it'll be called for every single menu item, but it seems menus are set up as taxonomies inside WordPress, and so you can use has_term() to determine if the item is in a particular menu, and get_nav_menu_locations() to pull ...
Top 50 recent answers are included

