• Resolved jelle65

    (@jelle65)


    Hello,

    I am using the divi-theme and within this theme is the funtion witch sets the viewport maximum = 1 and scaleble = 0. I need to change this into maximum = 3 en scaleble = 1.

    function et_add_viewport_meta(){
    echo ‘<meta name=”viewport” content=”width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0″ />’;
    }
    add_action( ‘wp_head’, ‘et_add_viewport_meta’ );

    I have put the following code in the Divi-child functions.php

    <?php
    function my_theme_enqueue_styles() {
    wp_enqueue_style( ‘parent-style’, get_template_directory_uri() . ‘/style.css’ );
    }
    add_action( ‘wp_enqueue_scripts’, ‘my_theme_enqueue_styles’ );

    function remove_my_action(){
    remove_action( ‘wp_head’, ‘et_add_viewport_meta’ );
    }
    add_action( ‘wp_head’, ‘remove_my_action’ );

    function et_add_viewport_meta(){
    echo ‘<meta name=”viewport” content=”width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0″ />’;
    }
    add_action( ‘wp_head’, ‘et_add_viewport_meta’ );

    But i get the error: Cannot redeclare et_add_viewport_meta() (previously declared in wp-content/themes/Divi-child/functions.php:14) Where line 14 is the “echo meta name…” line.

    Is there someone who can help me with this?

    Thanks in advance..

    • This topic was modified 1 year, 6 months ago by jelle65.
    • This topic was modified 1 year, 6 months ago by jelle65.
    • This topic was modified 1 year, 6 months ago by jelle65.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Just change the name of the function in your function.php file because you can’t have two functions that have the same name, even in different themes. Instead of ‘et_add_viewport_meta’, call it ‘et_child_add_viewport_meta’.

    oke, thank you, i did what you sugest and it did work a bit. Now it’s in the head but the parent-function is still there and folowing behind the child-function thereby overriding the child-function..

    <meta name=”viewport” content=”width=device-width, initial-scale=1.0, maximum-scale=3.0, user-scalable=1″ /><meta name=”viewport” content=”width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0″ />

    I somehow have to remove the origenal “function et_add_viewport_meta()” so the child will be the only function who is writing the viewport in the head..
    And yes, i did ad the remove function allso but that piece of code would not remove the origenal function from the head.

    Thanks again in advance..

    At least i am not getting anny errors anymore.. There is progresse.. 🙂

    • This reply was modified 1 year, 6 months ago by jelle65.

    Your original remove_action() code was correct, so add that back in, without changing the name of the function and that should remove the call to the parent themes function.

    It may be correct but it does not do the trick. The meta viewport in the head still is the old parent-funtion who is caling the shots and sits behind the new one.
    I did check it in the parent-funtion by changing the values of the viewport and they did allso change in the head when i reloaded it and viewed with the inspector..

    The complete line in the head is: <meta name=”viewport” content=”width=device-width, initial-scale=1.0, maximum-scale=3.0, user-scalable=1″ /><meta name=”viewport” content=”width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0″ /><link rel=”shortcut icon”

    The seccond ‘meta name’ comes from the parent. Can it be that it is called upon a seccond time, and overwrites my remove_action? Does’nt seem logic to me but i don’nt know.. 🙂

    Thanks again…

    Jelle

    Did get the correct lines from somewere else:

    function remove_viewport(){
    remove_action( ‘wp_head’, ‘et_add_viewport_meta’ );
    }
    add_action( ‘init’, ‘remove_viewport’ );

    function et_child_add_viewport_meta(){
    echo ‘<meta name=”viewport” content=”width=device-width, initial-scale=1.0, maximum-scale=3.0, user-scalable=1″ />’;
    }
    add_action( ‘wp_head’, ‘et_child_add_viewport_meta’ );

    Greatings..

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘remove_action’ is closed to new replies.