New answers tagged

0

You can include or require other php files in your functions.php file or you could consider using a plugin. Plugins will run on any theme, so if this isn't what you want, you could consider some code in your plugin to check if your theme is active or not, such as: <?php $theme = wp_get_theme(); // gets the current theme if ('twentytwelve' == ...


2

The functions.php is convention for a file that will be automatically loaded by WordPress. From there it is a normal PHP mechanics. You can further include any other PHP files in it. In some themes it is the only thing that a "root" functions.php does.


0

The classes are hardcoded in wp_generate_tag_cloud() function. Your only option there is to modify final string output via wp_generate_tag_cloud filter.


-1

The easiest way to get the site url without any sub-directories ( http://example.com/ instead of http://example.com/blog ), just use the backslash / For example, if you type: <a href="/">domain url</a> It will create a link that goes to your domain


0

It is a long question but it is possible for some developers I would like to give this answer. Example: I have two choose for my home layout Grid and List and I prefer Grid is default choosing. I should add default value in add_setting simple like this 'default' => 'grid'. $wp_customize->add_setting('yourtheme_home_layout_style', array( ...


1

You cannot query users by taxonomy. You will need to rethink your system. What would I do? Keep the taxonomies but use these only to output choosable values - wp_dropdown_categories() Save the selected value AS user meta, NOT AS taxonomies - update_user_meta() Now you can query users by that value - WP_User_Query() Example: This code would go to the ...


0

I have solved this by piecing things together in the database: add_action( 'gform_after_submission_6', 'add_registered_to_cart', 10, 2 ); function add_registered_to_cart($entry, $form) { // Get courses from form and push into array if existing $courses = []; $firstCourse = rgar($entry, '11'); $secondCourse = rgar($entry, '13'); if ...


1

If you want to concatenate function result into a string you should be returning it, not echoing it. Echo just sends it to output. Also you are making a typical mistake of confusing two flavor of WP template tags. Convention is the following: the_* template tags echo result immediately; get_the_* template tags return result. Internally former is usually ...


0

I was having the same issue. Somehow I was able to resolve it by using the following plugin https://wordpress.org/plugins/anything-popup/ You can give popup title/link/image and in the content echo the shortcode of the form. and call the popup shortcode where ever the text/link/image is placed. On clicking any of these, popup with the required content will ...


0

I found the solution. The string was added by the function wc_cart_totals_taxes_total_html which is documentated in the WooCommerce docs. It is located in the file .../woocommerce/includes/wc-cart-functions.phpon line 265. There you can change the text. It took me over a day to find it, but this worked.


0

No need for a routine here - use the WordPress hook system to "attach" a function that will run when a post is published: // https://codex.wordpress.org/Plugin_API/Action_Reference/publish_post function wpse_225371_post_published( $post_id, $post ) { // Do your thang } add_action( 'post_published', 'wpse_225371_post_published', 10, 2 );


1

Best way to check the option before setting the permalink is as follows: if ( get_option( 'page_for_posts' ) ) { echo '<a href="'.esc_url(get_permalink( get_option( 'page_for_posts' ) )).'">'.esc_html__( 'Blog', 'textdomain' ).'</a>'; } else { echo '<a href="'.esc_url( home_url( '/' ) ).'">'.esc_html__( 'Blog', 'textdomain' ...


-1

Just replace your short code function with given code. Then call it as usual. It should work perfectly now. //registering the shortcode to show testimonials function load_testimonials($a){ $atts = shortcode_atts( array( 'rand' => '', 'max' => '', 'id' => '', ), $a); $args = array( "post_type" => ...


1

Figured it out after thinking it through.. if (stripos(strtolower($template_filename), 'home') !== false) { $results[] = $template_name; }


0

Found the answer here: Reference Guide. It seems the default footer.php and header.php as well as some other template files are in wp-includes/theme-compat/


1

Add <?php get_footer(); ?> into index.php or the template you are using Then create footer.php and add in something like this: <?php /* Always have wp_footer() just before the closing </body> * tag of your theme, or you will break many plugins, which * generally use this hook to reference JavaScript files. */ ...


0

previous_post_link() and next_post_link() should work inside the the_content filter. There is nothing wrong with your code except you must return the value inside the filter instead of print. Otherwise I believe post link should be there at the beginning of content. previous_post_link() and next_post_link() print the output so consider using ...


0

There are various ways to do that, e.g. by moving the add_action for method b inside a class AwesomeClass{ private storedResult; private __construct(){ add_action( 'set_logged_in_cookie', array($this, 'a'),10,1); } Function a(p1){ //some interesting process with p1 // UPDATE $this->storedResult ...


2

The priority is related to other actions for the same hook. For example, if another plugin would implement add_action for wp_enqueue_scripts with a lower priority, they would have their scripts loaded in front of yours. You should check what scripts are inserted above yours and see if there is a css conflict.


0

This is how I bootstrapped youtube embeds in one of my projects. /** * Responsive Youtube embeds. */ add_filter( 'embed_oembed_html', function( $html, $url, $attr, $post_ID ) { if ( false !== stripos( $html, '<iframe ' ) && false !== stripos( $html, '.youtube.com/embed' ) ) { $html = sprintf('<div class="embed-responsive ...


0

Just as Zlatev recommended, I tried to get my data earlier and hook into the Yoast SEO plugin earlier. This worked fine for me. Had to write three new functions to get the desired data from my external data source, but now I have no more problems with setting title, open graph image and more. Lesson learned: Write (wrapper) functions to have your data ...


0

You can use the cat_is_ancestor_of() function to check for child categories. http://codex.wordpress.org/Function_Reference/cat_is_ancestor_of


2

Here's a workaround: First change the paginate_links() output type to: 'type' => 'array', Then we can collect the previous, current and next parts from the paginate_links() output. Here's a simple example where we target the relevant classes: $next = ''; $current = ''; $prev = ''; foreach( (array) $paginate_links as $link ) { ...


2

In general I wouldn't recommend modifying the original uploaded image files, just in case we might need to re-generate intermediate sizes. But let's see if it's possible :-) We can in general let WordPress choose the image editor, that depends on modules like GD or Imagick, through: $editor = wp_get_image_editor( $file ); but this can return an WP_Error ...


0

There is a plugin called Resize Image After Upload: <?php /* Plugin Name: Resize Image After Upload Plugin URI: https://wordpress.org/plugins/resize-image-after-upload/ Description: Simple plugin to automatically resize uploaded images to within specified maximum width and height. Also has option to force recompression of JPEGs. Configuration options ...


0

This answer could help you: http://wordpress.stackexchange.com/a/69287/92649 You would need to upload your image at a higher resolution than "large" to have that effect, though


2

Most obvious reason could be the fact wpseo_title filter is firing before you have saved your title. Try moving title_storage() call on a earlier stage like. The wp action should be a good candidate.


1

Your shortcode should look something like that function se224467_shotcode_star_rating( $atts ) { $a = shortcode_atts( array( 'grade' => 5, ), $atts ); $full_stars = floor( $a['grade'] ); // full stars $output = str_repeat( '<i class="fa fa-star"></i>', $full_stars ); // if not a whole number append a halt ...


0

I think you are looking for this- function star_rating( $atts ) { $max = 5; $atts = shortcode_atts( array( 'grade' => $max, // default ), $atts ); $star_icons = ''; $full_star = floor( $atts['grade'] ); for( $i=1; $i<=$full_star; $i++ ) { $star_icons .= '<i class="fa fa-star"></i>'; } $half_star = 0; if( (int) ...


3

Sidebars are stored in global variable $wp_registered_sidebars. You can get the sidebar properties using this variable. global $wp_registered_sidebars; if ( isset( $wp_registered_sidebars['sidebar-2'] ) ) { echo $wp_registered_sidebars['sidebar-2']['name']; } Note that do not use it too early, either on/after widgets_init hook or in a template ...


0

I just found the solution. use this code instead public function register_voguepay_woocommerce_payouts_dashboard_widget(){ add_meta_box( 'withdraw_to_bank', 'Withdraw to Bank', array($this, 'voguepay_woocommerce_payouts_dashboard_widget_display'), 'dashboard', 'side', 'high' ); } public function ...


0

Go to Settings/permalinks and click save. To prevent this from being a problem with plugins, or themes that insatiate CPT's/ Taxonomies there is the function flush_rewrite_rules. here is the link from the codex.


0

Million ways in WordPress to use home_url() or sister functions. The question to ask is: What function is a wrapper for other function? To summarize, if you like to concatenate you may use: get_bloginfo('url'); get_option('home'); If you like to have the control over scheme (http or https) get_site_url( $blog_id, $path, $scheme ); get_home_url( ...


3

When looking at either The Codex or Code Reference there's usually a little snippet at the bottom which says: Since: WordPress x.x.x If we take a look at wp_enqueue_script() for example we see toward the bottom above the contributor notes that it has been around: Since: WordPress 2.1.0 Now we can use the WordPress Release Chart to find out when ...


1

wp_enqueue_script is since Wordpress 2.1.0 https://developer.wordpress.org/reference/functions/wp_enqueue_script/ wp_enqueue_style is since Wordpress 2.6.0 https://developer.wordpress.org/reference/functions/wp_enqueue_style/ Found via a quick google


0

I think you might be jumping the gun with actively discarding the data here. What if next month trolls go away, you change your mind, and want all those featured images back? I would just suppress them on front end by editing template and making thumbnail output conditional or filtering API with something like this: if ( ! is_admin() ) { add_filter( ...


1

depth=n2 should be depth=2. n is just a "placeholder" and should be replaced by the actual integer value of your choice


2

I you want the script be enqueued on page-index.php and page-contact-us.php, then you must check that that page templates are used but you are checking if they are not used. Chagne this: if ( !is_page_template('page-templates/page-index.php') && !is_page_template('page-templates/page-contact-us.php') ) { with: if ( ...


0

Just in case someone got here looking for how to also add a Guest Description, here is my full implementation. If follows the same logic as the other answers, I just added a get_the_author_description filter and a function to overwrite the author Bio info (description). As the other solutions above, you pass it as a custom field (see image attached). ...


0

I would suggest opening CSV in Excel and use formatting to convert all dates to the same format and save CSV before using this for importing. This should avoid any development efforts.


-1

You can only get this email and verify if there is any user have this email then change this email by the correspond username like this $login ='anything@me.com'; if(is_email( $login )){ if( email_exists( $login )) { $userID__ = email_exists($login); $user_info_kim = get_userdata($userID__); $login = ...


0

According to Function Reference for wp_list_comments, you can set the arg Echo to false to return the list. I imagine the default walker will not echo the code if this is set to false. wp_list_comments(array('reverse_top_level' => false, 'echo' => false), $comments);


0

If you want to change the search behavior, then, all you need to do is add your own fields to the form <form role="search" method="get" id="searchform" action="http://www.test.dev/"> <div> <label for="s">Search for:</label> <input type="text" value="" name="s" id="s" /> <input type="hidden" value="1" name="sentence" /> ...


0

This requires a definition of what is "auto update", but in the most general sense, a plugin can do whatever any other part of wordpress can do therefor a plugin can trigger an auto update without human intervention. On the more practical side, this is very unlikely, and hiding the indication should be good enough for all practical usage. Still hiding ...


0

I have figured out how to do this. It was somewhat close to what ankittiwaari suggested, but he didn't give a few key details. When you pass a variable under data in an ajax call, it automatically makes it a $_POST request assuming you are calling method: 'post' So I did what ankittiwaari said and created <input type="hidden" value="<?= ...


0

You would use the handle of your enqueued scripts, ie, the first parameter of the wp_enqueue_script function used in WordPress for all your scripts... (if you are loading them another way you should use this function instead.) The handle for jQuery is... jquery actually jquery-core now. But each script queued will have it's own handle. A bit like a 'slug' ...


0

Assign the value of you $_POST variable to a html element or javascript variable in front-page.php like //html element <input type="hidden" value="<?= $_POST['variable']?>" id="post-variable"> or in javascript variable var postVariable = "<?= $_POST['variable']?>"; Now in ajax call, you can get the value as var myValue = ...



Top 50 recent answers are included