Hot answers tagged

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, ...


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 ...


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>'; } ?>


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 ...


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 ...


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 $...


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

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 ...


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 . $...


2

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


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 ) { $...


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 ...


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>'; } ...


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 ...


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 ...


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; } ...


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 ...


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(...


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 ) { $...


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!" ), '...



Only top voted, non community-wiki answers of a minimum length are eligible