New answers tagged

0

Solved it by altering the file disqus.php. First find function function dsq_output_count_js() { Add the following check before the function tries to output the JS if ( ! is_front_page() ) { ?> <script type="text/javascript"> I’m using this until Disqus created the option to configure this. Thanks for the help.


1

Using an URL to include a php file will usually not work. You will need a filesystem path. Depending on where you .php file is located (in this case the template directory), you could use: include( get_template_directory() . '/myfile.php' ); https://codex.wordpress.org/Function_Reference/get_template_directory


1

Sure. In your single.php or where you loop through the posts, start by getting the content: $content = get_the_content(); Then use a regex where you target anything within <h2> tags: $regex = '/<h2>(.*?)\<\/h2>/u'; And then use preg_match_all() to find all titles: preg_match_all($regex, $content, $table_of_content); This will ...


0

If all you have in your child theme is a style.css file and a functions.php file. I would suspect an issue in functions.php. if you used the information on this page Wodpress Child Themes to create your child theme. Then I would suspect an issue with your function names. Try appending your initials to the begging of all your function names and the hook call ...


0

I believe that you have neglected to create a menu on the Appearance > Menus panel in the WordPress admin dashboard and associate it with your registered 'header-nav' menu location. If I'm correct, the possible solutions might sound a little strange. Simply create a menu - the extraneous <div> should disappear even if you don't associate the new ...


0

That's because get_post_meta_by_key() isn't a WordPress function. What you're likely looking for is get_post_meta(): add_action( 'woocommerce_after_shop_loop_item', 'display_author' ); function display_author() { global $post; echo get_post_meta( $post->ID, 'author', true ); } Not tested, because I don't have a WooCommerce install handy (and ...


0

Input/output related security issue can be roughly sorted into two buckets: someone manages to read information they are not supposed to; someone manages to write information they are not supposed to. Localize is not capable of writing anything into site, so you are safe on that front. On the read side it's not much different from just echoing things ...


1

You can use the is_user_logged_in() function to check if the user is or not logged in the Dashboard. I do not know why you echo out a <script> tag, but if you want to integrate PHP & JavaScript altogether, I recommend you to take a look at https://codex.wordpress.org/AJAX_in_Plugins. This way you can pass data from the WordPress Back End to Front ...


4

<?php if ( is_user_logged_in() ) { echo '<script type="text/javascript">var logged_in=true;</script>'; } else { echo '<script type="text/javascript">var logged_in=false;</script>'; } ?>


0

Correct code: function tags_after_single_post_content($content) { $posttags = get_the_tags(); if ($posttags) { $array = []; foreach($posttags as $tag) { $array[] = '<a href="/tag/' . $tag->slug . '/">' . $tag->name . '</a>'; } $content .= 'Tags: ' . implode(', ', $array) . '<br>'; } return $content; } ...


0

Are you sure you want to do this in this manner? Normally a section like this might be written to the page template somehow and not called via the content editor. That being said, this should do what you need: add_shortcode( 'show_xyz_news', 'xyz_news_query' ); function xyz_news_query() { $args = array( 'posts_per_page' => 3, '...


2

You just have to add another element to the array (and then output it): function btn_shortcode( $atts, $content = null ) { $a = shortcode_atts( array( 'class' => 'button', 'href' => '#' ), $atts ); return '<a class="' . esc_attr($a['class']) . '" href="' . esc_attr($a['href']) . '">' . $content . '</a>'; } ...


3

The new function in your child theme's functions.php cannot override a function from the parent's functions.php file unless that function is written to be pluggable, i.e. declared with if (!function_exists('alterna_get_social_list')) Per the documentation on Child Themes and how they inherit from child functions.php files: Using functions.php Unlike ...


0

You can get current user ID easily using get_current_user_id(). $usersid = get_current_user_id(); $activity = $_POST['activity']; $reason = $_POST['reason']; $explanation = $_POST['explanation']; For your function f2user() you can change your code to this: $current_user = wp_get_current_user(); return $current_user->ID; According to ...


1

The way I do it. Note there may be a more straightforward way. Step 1 Add a custom query_varlike this to record the redirect from/to variables function my_custom_query_vars($vars){ //this allows you to store custom variables with rediect_from and rediect_to in the url $vars[] = 'redirect_from'; $vars[] = 'redirect_to'; return $vars; } ...


3

It seems that extract() function sets it to false if value is not provided. There might be a better way around it, but I've used workaround as follows function Test($atts) { extract(shortcode_atts(array( 'row' => null ), $atts)); $output = 'false'; if( in_array('row', $atts)) $output = 'true'; return $output; } ...


3

As far as I know you could hook into the filter image_send_to_editor like this: function html5_insert_image($html, $id, $caption, $title, $align, $url) { $url = wp_get_attachment_url($id); $html5 = "<figure id='post-$id media-$id' class='align-$align'>"; $html5 .= "<img src='$url' alt='$title' />"; $html5 .= "</figure>"; return $...


2

There's a filter called image_send_to_editor that lets you specify the markup. You will also need wp_get_attachment_metadata to retrieve width and height. It is called like this (untested): add_filter( 'image_send_to_editor', 'wpse_231693_img_markup', 10, 7 ); function wpse_231693_img_markup ($html, $id, $alt, $title, $align, $url, $size ) { $...


1

https://developer.wordpress.org/reference/hooks/wp_nav_menu_menu-slug_items/ function my_nav_menu_primary_navigation($items, $args) { $items .= '<li>Hello :D</li>'; return $items; } add_filter( "wp_nav_menu_{MENU SLUG}_items", "my_nav_menu_primary_navigation", 10, 2 ); find {MENU SLUG} EDIT: The "wp_nav_menu_menu-slug_item" filter ...


1

You're really close - get_header_image() returns the URL of the image, whereas header_image() echo's out the URL. Because you're setting your style tag in a variable and then echo'ing that, you need to use the function that returns the header image URL - so, like this: $banner = 'style="background-image:url('. get_header_image() .');"'; Using ...


0

http://src.wordpress-develop.dev/category/Markup/ or another link is not a post type archive page, it is a archive page. archive page is not a post type archive page. archive page access link like above, but post type archive page access link like: http://src.wordpress-develop.dev/(post-type) replace the (post-type) with the really post type. There is no ...


2

When 'is_post_type_archive()' return true? is_post_type_archive() returns true for custom post type archives and false for default posts. Use is_archive() to check for default posts.


2

There's a filter for the output $job_listings_output = apply_filters( 'job_manager_job_listings_output', ob_get_clean() ); so, you should just do add_filter('job_manager_job_listings_output','my_job_manager_job_listings_output'); function my_job_manager_job_listings_output($output) { $adsense_code = ' My adsense code'; return $output . $...


0

The full solution that works for me without modifying the Wordpress core is to clone the human_time_diff() function and place it inside functions.php as a renamed human_time_diff_chinese(), then swap all occurrence of human_time_diff() function with this new human_time_diff_chinese() function. function human_time_diff_chinese( $from, $to = '' ) { if ( ...


2

I don't think the name (typeahead bundle) may contain spaces.


1

the if(is_front_page()) will check if front page is being viewed, then load your css and meta slider . Codex documention <?php add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' ); function my_theme_enqueue_styles() { # added if(is_front_page()) wp_enqueue_style( 'parent-style', get_template_directory_uri(...


4

I ran your filter in my development area. It didn't work. Then I switched off the Yoast SEO plugin, which I knew was also messing with the page title. Then it worked. So my suggestion would be it is another plugin that is messing with it. In the case of Yoast, it was a filter call to pre_get_document_title that returned non empty. In that case ...


1

If you check out the source of human_time_diff: if ( $diff < HOUR_IN_SECONDS ) { $mins = round( $diff / MINUTE_IN_SECONDS ); if ( $mins <= 1 ) $mins = 1; /* translators: min=minute */ $since = sprintf( _n( '%s min', '%s mins', $mins ), $mins ); } elseif ( $diff < DAY_IN_SECONDS && $diff >= HOUR_IN_SECONDS ) { $...


0

I enqueued the child script the right way and made the first Reference Error (eltdGlobalVars) disappear as follows: In functions.php in child I removed lines that dequeue the script "search_and_go_elated_listing". Then I enqueued it using a copy of the function with the same name as the pluggable function in parent: "search_and_go_elated_listing_assets". ...


3

After some experimenting I came to the following suggestion: could it be, that the <title> tag is "hard coded" inside your parent theme's header.php? If that is the case, you could try to remove the <title> tag from your child theme's header.php (copy your parent's header.php into your child theme folder) and then add the theme support back ...


-3

------------------ you can try this way, not 100% correct function.php - add admin ajax url ----------------- function enqueue_script(){ wp_register_script('custom_scripts',get_template_directory_uri() . '/js/scripts.js'); wp_localize_script( 'custom_scripts', 'ajax_url', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ))); wp_localize_script( '...


0

You need to add the paged parameter to your WPQuery: $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; $query = new WP_Query( array( 'posts_per_page' => 5, 'paged' => $paged ) ); Here are the docs.


1

If you want to use a variable from a another context in a function, create a class: class CustomLog { private $debug_msg = ""; public function __construct( $msg ) { $this->debug_msg = $msg; } public function log() { error_log( $this->debug_msg, 0 ); } } add_action( 'init', [ new CustomLog( "Hi there!" ), '...


3

Having read your post from top to botom and bottom to top, you have in all probabilty a filter that is passing a title through the pre_get_document_title filter. The clue here the following statement: I've also tried pre_get_document_title, which does fire on page load, Looking at the soure code for wp_get_document_title(), we see the following code: ...


2

If the parent theme does not declare support for title-tag you can do it like this in child theme /** * Theme support should be added on `after_setup_theme` */ function add_theme_support_child() { add_theme_support( 'title-tag' ); } add_action( 'after_setup_theme', 'add_theme_support_child', 11 ); Filter document_title_parts expected return type ...


0

Okay! Finally, I was able to make it work. Below is the complete working code. add_filter( 'wp_insert_post_data' , 'modify_post_title' , '99', 2 ); // Grabs the inserted post data so you can modify it. function modify_post_title( $data ) { if($data['post_type'] == 'artist' && isset($_POST['acf']['field_573676a95d920'])) { // If the actual field ...


0

Seems pretty much simple: add_filter( 'get_comment_author_link', 'attach_city_to_author' ); function attach_city_to_author( $author ) { $city = get_comment_meta( get_comment_ID(), 'city', true ); if ( $city ) $author = $city; return $author; } Unless if you are adding the city name somewhere else and wanted to remove comment author name then ...


4

The Codex says: It's important to note that most WordPress functions properly prepare the data for output, and you don't need to escape again. For example the_permalink() already escapes the output with: echo esc_url( apply_filters( 'the_permalink', get_permalink( $post ), $post ) ); so you don't need to do that yourself here. But the ...


0

I don't know any other way There is a much, much better way to do this - custom fields. As per these instructions in the custom fields docs, let's say you use the field name iframe_url: <iframe src="<?php echo esc_url( get_post_meta( $post->ID, 'iframe_url', true ) ?>" width="960" height="540" frameborder="0" allowfullscreen="...


2

In WordPress 4.5.3, there's a foreach in wp-includes/post.php on line 1177 and no others around it, so I'm guessing this is the one that's triggering the error in your install on line 1172. This is inside the register_post_type() function, and it's looping through the taxonomies argument that you're sending through. Well... that you were meant to send ...


9

Each of the files you have mentioned are theme files. When you upgrade WordPress itself, it will not touch any themes (or plugins) you have installed, whether or not you have modified them. If this was a theme you created yourself, then you have no worries at all. However, if this was a theme created by someone else, for example a WordPress default theme, ...


0

Change the_field() to get_field() the_field() = echo get_field()



Top 50 recent answers are included