• Resolved stefanocps

    (@stefanocps)


    Hello i need to insert code in the head section and iht body section (tracking google code and similar)

    I don’t want to use a plugin and i want to write straigh tin the php file sof my theme

    I have created a child theme…with child function.php

    I have tried different tutorial form google , i set codes infunction-php but the site break down

    Any help?thanks

    this is site info

    ` wp-core
    
    version: 6.5
    site_language: en_US
    user_language: en_US
    timezone: Europe/Rome
    permalink: /%postname%/
    https_status: true
    multisite: false
    user_registration: 0
    blog_public: 1
    default_comment_status: open
    environment_type: production
    user_count: 2
    dotorg_communication: true wp-paths-sizes wordpress_path: /home/greenartcoin/domains/greenartcoin.eu/public_html
    wordpress_size: 123.85 MB (129862113 bytes)
    uploads_path: /home/greenartcoin/domains/greenartcoin.eu/public_html/wp-content/uploads
    uploads_size: 160.43 MB (168221888 bytes)
    themes_path: /home/greenartcoin/domains/greenartcoin.eu/public_html/wp-content/themes
    themes_size: 27.52 MB (28852296 bytes)
    plugins_path: /home/greenartcoin/domains/greenartcoin.eu/public_html/wp-content/plugins
    plugins_size: 136.39 MB (143010978 bytes)
    database_size: 58.38 MB (61210624 bytes)
    total_size: 506.55 MB (531157899 bytes) wp-active-theme name: Hello Elementor Child (hello-elementor-child)
    version: 3.0.1.1712417703
    author: Elementor Team
    author_website: https://elementor.com/?utm_source=wp-themes&utm_campaign=author-uri&utm_medium=wp-dash
    parent_theme: Hello Elementor (hello-elementor)
    theme_features: core-block-patterns, widgets-block-editor, menus, post-thumbnails, automatic-feed-links, title-tag, html5, custom-logo, editor-style, align-wide, woocommerce, wc-product-gallery-zoom, wc-product-gallery-lightbox, wc-product-gallery-slider
    theme_path: /home/greenartcoin/domains/greenartcoin.eu/public_html/wp-content/themes/hello-elementor-child
    auto_update: Disabled wp-parent-theme name: Hello Elementor (hello-elementor)
    version: 3.0.1
    author: Elementor Team
    author_website: https://elementor.com/?utm_source=wp-themes&utm_campaign=author-uri&utm_medium=wp-dash
    theme_path: /home/greenartcoin/domains/greenartcoin.eu/public_html/wp-content/themes/hello-elementor
    auto_update: Disabled wp-themes-inactive (2) Astra: version: 4.6.11, author: Brainstorm Force, Auto-updates disabled
    Kadence: version: 1.2.3, author: Kadence WP, Auto-updates disabled wp-plugins-active (9) Complianz | GDPR/CCPA Cookie Consent: version: 7.0.4, author: Really Simple Plugins, Auto-updates disabled
    Converter for Media: version: 5.12.3, author: matt plugins, Auto-updates disabled
    Elementor: version: 3.20.3, author: Elementor.com, Auto-updates disabled
    GTranslate: version: 3.0.6, author: Translate AI Multilingual Solutions, Auto-updates disabled
    LiteSpeed Cache: version: 6.1, author: LiteSpeed Technologies, Auto-updates enabled
    Site Kit by Google: version: 1.123.1, author: Google, Auto-updates enabled
    WPCode Lite: version: 2.1.11, author: WPCode, Auto-updates disabled
    WPForms Lite: version: 1.8.7.2, author: WPForms, Auto-updates disabled
    WP Meta SEO: version: 4.5.11, author: JoomUnited, Auto-updates disabled wp-plugins-inactive (2) Kadence Blocks – Gutenberg Blocks for Page Builder Features: version: 3.2.33, author: Kadence WP, Auto-updates disabled
    Visualizer: Tables and Charts for WordPress: version: 3.10.11, author: Themeisle, Auto-updates disabled wp-media image_editor: WP_Image_Editor_Imagick
    imagick_module_version: 1809
    imagemagick_version: ImageMagick 7.1.1-19 Q16-HDRI x86_64 21601 https://imagemagick.org
    imagick_version: 3.7.0
    file_uploads: 1
    post_max_size: 64M
    upload_max_filesize: 64M
    max_effective_size: 64 MB
    max_file_uploads: 20
    imagick_limits:
    imagick::RESOURCETYPE_AREA: 250 GB
    imagick::RESOURCETYPE_DISK: 9.2233720368548E+18
    imagick::RESOURCETYPE_FILE: 491512
    imagick::RESOURCETYPE_MAP: 125 GB
    imagick::RESOURCETYPE_MEMORY: 62 GB
    imagick::RESOURCETYPE_THREAD: 1
    imagick::RESOURCETYPE_TIME: 9.2233720368548E+18
    imagemagick_file_formats: 3FR, 3G2, 3GP, A, AAI, AI, APNG, ART, ARW, ASHLAR, AVI, AVIF, AVS, B, BAYER, BAYERA, BGR, BGRA, BGRO, BIE, BMP, BMP2, BMP3, BRF, C, CAL, CALS, CANVAS, CAPTION, CIN, CIP, CLIP, CMYK, CMYKA, CR2, CR3, CRW, CUBE, CUR, CUT, DATA, DCM, DCR, DCRAW, DCX, DDS, DFONT, DNG, DOT, DPX, DXT1, DXT5, EPDF, EPI, EPS, EPS2, EPS3, EPSF, EPSI, EPT, EPT2, EPT3, ERF, EXR, FARBFELD, FAX, FF, FILE, FITS, FL32, FLV, FRACTAL, FTP, FTS, FTXT, G, G3, G4, GIF, GIF87, GRADIENT, GRAY, GRAYA, GROUP4, GV, HALD, HDR, HEIC, HEIF, HISTOGRAM, HRZ, HTM, HTML, HTTP, HTTPS, ICB, ICO, ICON, IIQ, INFO, INLINE, IPL, ISOBRL, ISOBRL6, J2C, J2K, JBG, JBIG, JNG, JNX, JP2, JPC, JPE, JPEG, JPG, JPM, JPS, JPT, JSON, K, K25, KDC, LABEL, M, M2V, M4V, MAC, MAP, MASK, MAT, MATTE, MEF, MIFF, MKV, MNG, MONO, MOV, MP4, MPC, MPEG, MPG, MPO, MRW, MSL, MSVG, MTV, MVG, NEF, NRW, NULL, O, ORA, ORF, OTB, OTF, PAL, PALM, PAM, PANGO, PATTERN, PBM, PCD, PCDS, PCL, PCT, PCX, PDB, PDF, PDFA, PEF, PES, PFA, PFB, PFM, PGM, PGX, PHM, PICON, PICT, PIX, PJPEG, PLASMA, PNG, PNG00, PNG24, PNG32, PNG48, PNG64, PNG8, PNM, POCKETMOD, PPM, PS, PS2, PS3, PSB, PSD, PTIF, PWP, QOI, R, RADIAL-GRADIENT, RAF, RAS, RAW, RGB, RGB565, RGBA, RGBO, RGF, RLA, RLE, RMF, RSVG, RW2, SCR, SCREENSHOT, SCT, SFW, SGI, SHTML, SIX, SIXEL, SPARSE-COLOR, SR2, SRF, STEGANO, STRIMG, SUN, SVG, SVGZ, TEXT, TGA, THUMBNAIL, TIFF, TIFF64, TILE, TIM, TM2, TTC, TTF, TXT, UBRL, UBRL6, UIL, UYVY, VDA, VICAR, VID, VIFF, VIPS, VST, WBMP, WEBM, WEBP, WMF, WMV, WMZ, WPG, X, X3F, XBM, XC, XCF, XPM, XPS, XV, XWD, Y, YAML, YCbCr, YCbCrA, YUV
    gd_version: 2.3.3
    gd_formats: GIF, JPEG, PNG, WebP, BMP, AVIF, XPM
    ghostscript_version: unknown wp-server server_architecture: Linux 4.18.0-477.13.1.lve.el8.x86_64 x86_64
    httpd_software: LiteSpeed
    php_version: 8.2.16 64bit
    php_sapi: litespeed
    max_input_variables: 1000
    time_limit: 30
    memory_limit: 128M
    admin_memory_limit: 256M
    max_input_time: 60
    upload_max_filesize: 64M
    php_post_max_size: 64M
    curl_version: 7.87.0 OpenSSL/1.1.1w
    suhosin: false
    imagick_availability: true
    pretty_permalinks: true
    htaccess_extra_rules: true
    current: 2024-04-07T11:09:53+00:00
    utc-time: Sunday, 07-Apr-24 11:09:53 UTC
    server-time: 2024-04-07T13:09:51+02:00 wp-database extension: mysqli
    server_version: 10.6.17-MariaDB-cll-lve
    client_version: mysqlnd 8.2.16
    max_allowed_packet: 67108864
    max_connections: 151 wp-constants WP_HOME: undefined
    WP_SITEURL: undefined
    WP_CONTENT_DIR: /home/greenartcoin/domains/greenartcoin.eu/public_html/wp-content
    WP_PLUGIN_DIR: /home/greenartcoin/domains/greenartcoin.eu/public_html/wp-content/plugins
    WP_MEMORY_LIMIT: 40M
    WP_MAX_MEMORY_LIMIT: 256M
    WP_DEBUG: false
    WP_DEBUG_DISPLAY: true
    WP_DEBUG_LOG: false
    SCRIPT_DEBUG: false
    WP_CACHE: true
    CONCATENATE_SCRIPTS: false
    COMPRESS_SCRIPTS: undefined
    COMPRESS_CSS: undefined
    WP_ENVIRONMENT_TYPE: Undefined
    WP_DEVELOPMENT_MODE: undefined
    DB_CHARSET: utf8
    DB_COLLATE: undefined wp-filesystem wordpress: writable
    wp-content: writable
    uploads: writable
    plugins: writable
    themes: writable google-site-kit version: 1.123.1
    php_version: 8.2.16
    wp_version: 6.5
    reference_url: https://www.greenartcoin.eu
    amp_mode: no
    site_status: connected-site
    user_status: authenticated
    verification_status: verified-file
    connected_user_count: 1
    active_modules: site-verification, search-console, analytics-4, pagespeed-insights
    recoverable_modules: none
    required_scopes:
    openid: ✅
    https://www.googleapis.com/auth/userinfo.profile: ✅
    https://www.googleapis.com/auth/userinfo.email: ✅
    https://www.googleapis.com/auth/siteverification: ✅
    https://www.googleapis.com/auth/webmasters: ✅
    https://www.googleapis.com/auth/analytics.readonly: ✅
    https://www.googleapis.com/auth/tagmanager.readonly: ✅
    capabilities:
    googlesitekit_authenticate: ✅
    googlesitekit_setup: ✅
    googlesitekit_view_posts_insights: ✅
    googlesitekit_view_dashboard: ✅
    googlesitekit_manage_options: ✅
    googlesitekit_update_plugins: ✅
    googlesitekit_view_splash: ✅
    googlesitekit_view_authenticated_dashboard: ✅
    googlesitekit_view_wp_dashboard_widget: ✅
    googlesitekit_view_admin_bar_menu: ✅
    googlesitekit_view_shared_dashboard: ⭕
    googlesitekit_read_shared_module_data::["search-console"]: ⭕
    googlesitekit_read_shared_module_data::["analytics-4"]: ⭕
    googlesitekit_read_shared_module_data::["pagespeed-insights"]: ⭕
    googlesitekit_manage_module_sharing_options::["search-console"]: ✅
    googlesitekit_manage_module_sharing_options::["analytics-4"]: ✅
    googlesitekit_manage_module_sharing_options::["pagespeed-insights"]: ✅
    googlesitekit_delegate_module_sharing_management::["search-console"]: ✅
    googlesitekit_delegate_module_sharing_management::["analytics-4"]: ✅
    googlesitekit_delegate_module_sharing_management::["pagespeed-insights"]: ⭕
    enabled_features:
    adsModule: ⭕
    audienceSegmentation: ⭕
    conversionInfra: ⭕
    ga4AdSenseIntegration: ⭕
    gm3Components: ⭕
    search-console_shared_roles: none
    search-console_management: owner
    analytics-4_shared_roles: none
    analytics-4_management: owner
    pagespeed-insights_shared_roles: none
    pagespeed-insights_management: all_admins
    search_console_property: https://www.greenartcoin.eu/
    analytics_4_account_id: 1957•••••
    analytics_4_ads_conversion_id: none
    analytics_4_property_id: 3782962••
    analytics_4_web_data_stream_id: 5260••••••
    analytics_4_measurement_id: G-CK••••••••
    analytics_4_use_snippet: yes
    analytics_4_available_custom_dimensions: none wpforms version: 1.8.7.2
    lite: 5 April 2023 at 20:38
    upload_dir: Writable
    total_forms: 3
    total_submissions: 1086

    The page I need help with: [log in to see the link]

Viewing 9 replies - 1 through 9 (of 9 total)
  • Hello,

    The simplest solution is to add it in header.php and footer.php file. In header.php, you can add it before </head> and in footer.php you can add the footer script before </body>

    However, the downside is when the theme is updated, you will need to add the codes again.

    Thread Starter stefanocps

    (@stefanocps)

    so this is not a solution

    unlesss i can do that in the child header.php and footer.php

    • This reply was modified 1 year, 9 months ago by stefanocps.

    Yes you can. Created header.php file inside the child theme, copy all the code of header.php from parent theme and paste it in header.php in child theme. Then add your code before </head>. This way it won’t be affected even if you update theme.

    Thread Starter stefanocps

    (@stefanocps)

    but if i copy ALL the code, this file will entirely replace the original header.php, and when th eoriginal.php will be updated..i

    will not get update on my site?

    Here’s a better approach.

    In your functions.php, add this code

    function analytics_code() {
        ?>
        add your analytics code here
        <?php
    }
    add_action('wp_head', 'analytics_code', 999);

    This will add your code before </head>. The 999 priority ensure that your code is last thing in the <head> i.e. it will be just before </head>.

    Thread Starter stefanocps

    (@stefanocps)

    ok thank you i’ll try

    and for body?

    Thread Starter stefanocps

    (@stefanocps)

    that code works! how can i check if the code for analytics, the tyag i hav set…are working?

    For body, use this:

    function body_code() {
        ?>
        add your code here
        <?php
    }
    add_action('wp_footer', 'body_code', 999);

    It will add your code just before </body> tags. Don’t forget to replace add your code here with your code.

    Thread Starter stefanocps

    (@stefanocps)

    great, they both work. is there a way to chack that the code i have inserte dis really fetched?

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘error when adding code tu function.php’ is closed to new replies.