• Sarah H

    (@sarahrbcom)


    I’m trying to add a function to my child theme that will add a specific Title to the top of the page, below the header and above the page title, based off what section of the website it is.

    I found this code on Stack Overflow for adding custom body classes, not overly helpful BUT IT DOES detect specific parts of the URL and uses that to trigger the filter. This logic works great for me but I need to figure out how to hook it into OceanWP in the right place (ocean_after_header?) and then insert my content (an H2 with title text).

    add_filter( 'body_class', 'custom_class' );
        function custom_class( $classes ) {
            if(strpos($_SERVER['REQUEST_URI'], "special") !== false){
                $classes[] = 'myclass';
            }
            return $classes;
        }

    This is as far as I got with my experiments but I know it’s not right…

    add_filter( 'ocean_after_header', 'add_service_title' );
        function add_service_title() {
            if(strpos($_SERVER['REQUEST_URI'], "architecture-engineering") !== false){
                <h2 class="service-title">Architecture and Engineering</h2>
            }
        }

    I’ve also tried this via Ocean Hooks, but it’s too limited and only allows conditional logic based of specific pages. I have four different sections of the website with four different titles that need apply to a parent page and all of its children, including any new ones that are created in the future

Viewing 1 replies (of 1 total)
  • Amit Singh

    (@apprimit)

    Hello Sarah,

    Try to use the below code and check it works or not –

    add_action( 'ocean_after_header', 'add_service_title' );
     function add_service_title() {
        if(strpos($_SERVER['REQUEST_URI'], "architecture-engineering") !== false){
           <h2 class="service-title">Architecture and Engineering</h2>
        }
     }
Viewing 1 replies (of 1 total)
  • The topic ‘Hooking into ocean_after_header’ is closed to new replies.